【发布时间】:2018-11-29 16:31:44
【问题描述】:
如何根据我的特定购物车条件强制应用免费送货?
我的条件(有效):
- 如果 购物车中有 4 件商品 并且购物车中没有任何商品来自类别圣诞节...
我也无法申请免费送货。我需要使用woocommerce_cart_calculate_fees 挂钩来执行此操作吗?
add_filter( 'woocommerce_calculated_total', 'calculated_total', 10, 2 );
function calculated_total( $total, $cart ) {
$taster_count = 4;
$item_count = $cart->get_cart_contents_count();
$chistm_count = 0;
foreach ( $cart->get_cart() as $cart_item ) {
if ( ! has_term( 'christmas', 'product_cat', $cart_item['product_id'] ) ) {
$chistm_count += $cart_item['quantity'];
}
}
if( $taster_count == $item_count && $chistm_count == $taster_count )
$discount = 3.00;
$cart->add_fee( 'You subscribed! Free shipping applied!', -$discount);
return 10;
return $total;
}
【问题讨论】:
标签: php wordpress woocommerce shopping-cart hook-woocommerce