1 回答
TA贡献1880条经验 获得超4个赞
以下将根据商品数量进行百分比折扣:
add_action( 'woocommerce_cart_calculate_fees','cart_quantity_discount' );
function cart_quantity_discount( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$discount = 0; // Initializing
$percent = 10; // Percentage
// Loop through cat items
foreach ( $cart->get_cart() as $cart_item ) {
$subtotal = $cart_item['line_total'];
// Calculation by Item based on quantity
if( $cart_item['quantity'] > 17 ) {
$discount += $cart_item['line_total'] * $percent / 100;
}
}
if( $discount > 0 ) {
$cart->add_fee( __( "Item quantity discount", "woocommerce" ), -$discount, true );
}
}
代码位于活动子主题(或活动主题)的functions.php 文件中。它应该有效。
- 1 回答
- 0 关注
- 113 浏览
添加回答
举报