0

我有两个文件,第一个是front page.php,第二个是functions.php。在提交提交按钮“customcart”上,我正在尝试执行此 if block 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;
}
}
?>
4

1 回答 1

0

根据您的 html 代码,您应该替换

if (isset($_POST['addcustomcarts']))

if (isset($_POST['customcart']))
于 2013-10-23T13:34:11.550 回答