【发布时间】:2019-01-12 16:46:00
【问题描述】:
function hidding_coupon_field_on_cart_for_a_category($enabled) {
// Set your special category name, slug or ID here:
$special_cat = 'clothing';
$bool = false;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$wc_product = $cart_item['data'];
// Woocommerce compatibility
$product_id = method_exists( $wc_product, 'get_id' ) ? $wc_product->get_id() : $wc_product->id;
if ( has_term( $special_cat, 'product_cat', $product_id ) )
$bool = true;
}
if ( $bool && is_cart() ) {
$enabled = false;
}
return $enabled;
}
add_filter( 'woocommerce_coupons_enabled', 'hidding_coupon_field_on_cart_for_a_category' );
找到这个 sn-p 并且效果很好,但是如果我有一个变量而不是一个简单的产品,那么类别隐藏似乎不再起作用了。
$special_cat = 'prints';
$product_id = array('9461', '9597');
同时排除主要产品 id 和变体 id 也不起作用。有人有想法吗?
【问题讨论】:
标签: php wordpress woocommerce custom-taxonomy coupon