小编Osm*_*man的帖子

购物车折扣基于购物车项目计数,仅适用于非销售商品

在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);
} 
Run Code Online (Sandbox Code Playgroud)

但我不知道如何仅对未售出的商品应用折扣.我怎样才能实现它?

谢谢.

php wordpress cart discount woocommerce

5
推荐指数
1
解决办法
631
查看次数

标签 统计

cart ×1

discount ×1

php ×1

woocommerce ×1

wordpress ×1