這個自定義掛鉤函數應該做你期望的。您可以根據個別料品數量在其中設定您的累進折扣限額。
這裏是你的活躍兒童主題(或主題)的function.php文件中的代碼
## Tested and works on WooCommerce 2.6.x and 3.0+
add_action('woocommerce_cart_calculate_fees', 'progressive_discount_by_item_quantity', 10, 1);
function progressive_discount_by_item_quantity($cart_obj) {
if (is_admin() && ! defined('DOING_AJAX'))
return;
# Progressive quantity until quantity 3 is reached (here)
# After this quantity limit, the discount by item is fixed
# No discount is applied when item quantity is equal to 1
// Set HERE the progressive limit quantity discount
$progressive_limit_qty = 3; // <== <== <== <== <== <== <== <== <== <== <==
$discount = 0;
foreach($cart_obj->get_cart() as $cart_item_key => $item_values){
$qty = $item_values['quantity'];
if($qty =< $progressive_limit_qty)
$param = $qty; // Progressive
else
$param = $progressive_limit_qty; // Fixed
## Calculation ##
$discount -= 5 * $qty * ($param - 1);
}
if($discount < 0)
$cart_obj->add_fee(__('Quantity discount'), $discount); // Discount
}
代碼去或者還有任何插件文件。
經過測試,適用於WooCommerce 2.6.x和3.0+