【发布时间】:2017-06-05 16:25:53
【问题描述】:
在 WooCommerce 中,我想专门为那些不销售的产品提供 10% 的折扣。如果购物车商品数量为 5 件或更多商品且未在售,则我给予 10% 的折扣。
我在这里使用以下代码根据购物车商品数量限制获得折扣:
add_action('woocommerce_cart_calculate_fees' , 'add_custom_fees');
/**
* Add custom fee if more than three article
* @param WC_Cart $cart
*/
function add_custom_fees( WC_Cart $cart ){
if( $cart->cart_contents_count < 5 ){
return;
}
// Calculate the amount to reduce
$discount = $cart->subtotal * 0.1;
$cart->add_fee( '10% discount', -$discount);
}
但我不知道如何仅对非销售商品应用折扣。我怎样才能实现它?
谢谢。
【问题讨论】:
-
more than 5 products等于$cart->cart_contents_count <= 5 -
您有问题吗?这行得通吗?到底是什么问题?
-
我认为你最好在 Code Review 上询问。
-
@H.Pauwelyn 好心,这个问题就在 StackOverFlow 上……谢谢。
标签: php wordpress woocommerce cart discount