2
我正在嘗試爲WooCommerce提供一個簡單的折扣代碼,在購買之前給您一個百分比折扣。比方說,如果你增加產品價值$ 100,您獲得2%的折扣,如果你增加產品價值$ 250,你得到4%等基於購物車金額的漸進式百分比折扣
我發現的唯一的事情是這樣的:
// Hook before calculate fees
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 < 3){
return;
}
// Calculate the amount to reduce
$discount = $cart->subtotal * 0.1;
$cart->add_fee('You have more than 3 items in your cart, a 10% discount has been added.', -$discount);
}
,但不能設法使其與修改與價格掛鉤的工作。
我該如何做到這一點?
感謝。
哇,那真的很有幫助。非常感謝! –
有什麼方法可以在購物車中顯示折扣嗎? –
折扣只出現在我的結帳頁面,購物車價格顯示是沒有折扣的全價。 –