【问题标题】:Woocommerce force free delivery based on cart count and cart categoriesWoocommerce 根据购物车数量和购物车类别强制免费送货
【发布时间】: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


    【解决方案1】:

    你可以用woocommerce_package_rates钩子代替woocommerce_calculated_total

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

    希望这能解决问题。

    【讨论】:

    • 抱歉,您能否再解释一下取消设置除免费送货以外的所有方法是什么意思?
    • 此过滤器挂钩将为您提供所有可用运费的数组,只需取消该数组中除此之外的所有其他值并返回该数组。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-25
    • 1970-01-01
    • 1970-01-01
    • 2017-07-07
    • 2020-10-12
    • 2019-09-18
    • 2020-11-24
    相关资源
    最近更新 更多