【发布时间】:2016-12-16 08:27:42
【问题描述】:
我正在尝试为 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);
}
但是无法设法使其与修改钩子的价格一起工作。
我怎样才能做到这一点?
【问题讨论】:
标签: php wordpress woocommerce cart discount