最初の 1 つは front page.php、2 番目は functions.php の 2 つのファイルがあります。送信ボタン「customcart」で、これを実行しようとしています if(isset($_POST['addcustomcarts'])) をブロックします。誰でもこれについて何か考えがあります。私はWordPressを初めて使用します。私はたくさん試しましたが、何もわかりません。
フロントページ.php
<form name="addcustomcart" id="customcart" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<a href="/cutting-edge_server/wordpress_theme/cart/"> <input type="submit" name="customcart" value="Add To Cart"></a>
</form>
関数.php
if ( !defined('ABSPATH')) exit;
/**
*
* WARNING: Please do not edit this file in any way
*
* load the theme function files
*/
$template_directory = get_template_directory();
require ( $template_directory . '/core/includes/functions.php' );
require ( $template_directory . '/core/includes/theme-options.php' );
require ( $template_directory . '/core/includes/post-custom-meta.php' );
require ( $template_directory . '/core/includes/tha-theme-hooks.php' );
require ( $template_directory . '/core/includes/hooks.php' );
require ( $template_directory . '/core/includes/version.php' );
require ( $template_directory . '/core/includes/upsell/theme-upsell.php' );
if (isset($_POST['addcustomcarts']))
{
add_filter('woocommerce_before_cart', 'customcart');
function customcart( ) {
global $woocommerce;
$my_post = array(
'post_title' => 'My post',
'post_content' => 'This is my post.',
'post_status' => 'publish',
'post_author' => 1,
'post_type' =>'product',
);
// Insert the post into the database
$product_ID=wp_insert_post( $my_post );
add_post_meta($product_ID, '_regular_price', 100, $unique);
add_post_meta($product_ID, '_price', 100, $unique);
add_post_meta($product_ID, '_stock_status', 'instock', $unique);
echo $woocommerce->cart->add_to_cart( $product_ID, $quantity=1 );
//exit;
// wp_redirect("".home_url('cart')."&add-to-cart=".$product_ID."");
//global $wpdb;
//$wpdb->query
//exit;
//exit;
}
}
?>