gpt4 book ai didi

php - fatal error : Call to a member function get_cart_contents_count() on a non-object in/functions. php 在第 413 行

转载 作者:行者123 更新时间:2023-12-03 07:58:30 32 4
gpt4 key购买 nike

on line 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' );

如何解决此错误?

当我运行此代码时,出现 fatal error 。我认为
$woocommerce->cart->get_cart_contents_count(); 

做空。

那么我该如何解决这个错误呢?请帮我

最佳答案

最后我找到了答案

Fatal error: Call to a member function get_cart_contents_count() on a non-object


function a000_remove_bundles_counting(){

global $woocommerce_bundles;
remove_filter( 'woocommerce_cart_contents_count',
array( $woocommerce_bundles->display, 'woo_bundles_cart_contents_count' ) );
}
add_action( 'init', 'a000_remove_bundles_counting' );

disable the Bundles filter before simultaneously adding own via d000_cart_contents_count


function d000_cart_contents_count( $count ) {
global $woocommerce;
$cat_check = false;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) { //foreach

$product = $cart_item['data'];

if ( has_term( 'tv', 'product_tag', $product->id ) ) {//search product_cat
$cat_check = true;
// break because we only need one "true" to matter here
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' );

} // end search product_cat
}// end foreach



return $count;
}
add_filter( 'woocommerce_cart_contents_count',
'd000_cart_contents_count' );

关于php - fatal error : Call to a member function get_cart_contents_count() on a non-object in/functions. php 在第 413 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44403572/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com