On设置发布后按钮执行if block?

时间:2013-10-23 13:05:18

标签: php wordpress

我有两个文件,第一个是front page.php,第二个是functions.php。在帖子提交按钮“customcart”,我试图执行此if if if if(isset($ _ POST ['addcustomcarts']))。任何人都对此有任何想法,我对WordPress很新。我已经尝试了很多,但没有得到任何想法。

前page.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> 

的functions.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;
}
}
?>

1 个答案:

答案 0 :(得分:0)

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

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

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