Woocommerce 根据购物车数量和购物车类别强制免费送货

Woocommerce force free delivery based on cart count and cart categories

如何根据我的特定购物车条件强制应用免费送货

我的条件(有效):

我也无法申请免运费。我需要使用 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;
}

您可以使用 woocommerce_package_rates 钩子代替 woocommerce_calculated_total

根据您的情况取消设置除免费送货外的所有方法。

希望这能奏效。