【发布时间】:2017-11-08 06:30:25
【问题描述】:
在线 413 $product_count = $woocommerce->cart->get_cart_contents_count();
function wc_sell_only_states( $states ) {
// set our flag to be false until we find a product in that category
$cat_check = false;
global $woocommerce;
ob_start();
//==========================================AAAAAAAAAAAAAAAAA
$product_count = $woocommerce->cart->get_cart_contents_count();
if($product_count > 0){
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) { //foreach
$product = $cart_item['data'];
// replace 'membership' with your category's slug
if ( has_term( 'VIP', 'product_tag', $product->id ) ) {//search product_cat
$cat_check = true;
// break because we only need one "true" to matter here
//////////////////////////////////////////////////////////////////////////////////////
if (!function_exists('soosti_add_checkout_content')) {
function soosti_add_checkout_content() { // skyverge function
echo '<p style="color:#F31114">Attention: In your shopping cart hava Special product that only shipping to <b>California</b>...</p>';
}//end skyverge function
}
add_action( 'woocommerce_before_checkout_form', 'soosti_add_checkout_content', 12 );
//-------------------------
//---------------------------
if (!function_exists('woo_override_checkout_fields')) {
function woo_override_checkout_fields( $fields ) { // woo_override_checkout_fields Function
$fields['billing']['billing_country'] = array(
'type' => 'select',
'label' => __('Country', 'woocommerce'),
'options' => array('US' => 'United States(US)')
);
$fields['billing']['billing_state'] = array(
'type' => 'select',
'label' => __('State', 'woocommerce'),
'options' => array('CA' => 'California(CA)')
);
return $fields;
} //end woo_override_checkout_fields Function
}
add_filter( 'woocommerce_checkout_fields' , 'woo_override_checkout_fields' );
如何解决这个错误?
当我运行此代码时,我得到一个致命错误。我觉得
$woocommerce->cart->get_cart_contents_count();
清空。
那么我该如何解决这个错误呢?请帮帮我
【问题讨论】:
标签: php error-handling woocommerce fatal-error