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' );
///////////////////////////////////////////////////
//////////////////////////////////////////////////////
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( 'VIP', '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' );
首先您设置产品标签“VIP 或您喜欢的任何内容,然后您将其添加到代码中
if ( has_term( 'VIP', 'product_tag', $product->id ) ) {//search product_cat
$cat_check = true;
}
在此功能中查找是否有任何带有“VIP”产品标签的产品。
和$cat_check = true;
然后在这个函数里面我们添加函数
woo_override_checkout_fields( $fields ) 功能设置受限
country 作为发货国家字段。
内部woo_override_checkout_fields( $fields ) { }
设置您要显示的国家/地区
$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)')
);