【发布时间】:2017-12-29 13:53:16
【问题描述】:
如果购物车中有来自特定类别的产品,我正在尝试自动添加优惠券代码。显示折扣金额后,价格必须在总计中更新。
但我看不到总数的任何变化,请帮助我。
我的代码:
add_action('wc_cart_product_subtotal' , 'getsubtotalc');
function getsubtotalc ($product_subtotal, $_product, $quantity, $object) {
if( is_cart() || is_checkout() ) {
global $woocommerce, $product;
global $total_qty;
/*$coupon_code = 'drawer';
if ( $woocommerce->cart->has_discount( $coupon_code ) ) return;*/
foreach ( $woocommerce->cart->cart_contents as $product ) {
if( has_term( array('t-shirts-d','socks-d','joggers-d','boxers-d'), 'product_cat', $cart_item['product_id'] ) ){
$coupon_code = 'drawer';
if (!$woocommerce->cart->add_discount( sanitize_text_field( $coupon_code))) {
$woocommerce->show_messages();
}
echo '<div class="woocommerce_message"><strong>The number of Product in your order is greater than 10 so a 10% Discount has been Applied!</strong>
</div>';
}
}
}
}
谢谢
【问题讨论】:
标签: php wordpress woocommerce categories coupon