text 根据购物车小计更改woocommerce运费

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 根据购物车小计更改woocommerce运费相关的知识,希望对你有一定的参考价值。

<?php
add_filter('woocommerce_package_rates','xmit_subtotal_based_tiered_shipping', 10, 2 );
function xmit_subtotal_based_tiered_shipping( $rates, $package ){
    /* set the subtotal amounts to be reached for each shipping tier */
    $threshold1 = 50;
    $threshold2 = 100;
    $subtotal = WC()->cart->subtotal;

    if ( $subtotal < $threshold1 ) 
    { // Below 50 ('flat_rate:4' is enabled)
        unset( $rates['flat_rate:7'] );
        unset( $rates['flat_rate:9'] );
    } 
    elseif ( $subtotal >= $threshold1 && $subtotal < $threshold2 ) 
    { // Starting from 50 and below 100 ('flat_rate:7' is enabled)
        unset( $rates['flat_rate:4'] );
        unset( $rates['flat_rate:9'] ); 
    } 
    elseif ( $subtotal >= $threshold2 ) 
    { // Starting from 100 and up ('flat_rate:9' is enabled)
        unset( $rates['flat_rate:4'] );
        unset( $rates['flat_rate:7'] );  
    }
    return $rates;
}
In Woocommerce -> Settings -> Shipping, set up a Shipping Zone for Standard Shipping.

Add Shipping methods, in this case three: Standard Shipping ($7), Discounted Shipping ($5), and Free Shipping ($0).

Add the PHP to functions.php. To find out the id # of the rates, inspect the shipping methods in your browser;
the data-id of the table row for each is what has to go into the 'flat_rate:x' string.

以上是关于text 根据购物车小计更改woocommerce运费的主要内容,如果未能解决你的问题,请参考以下文章

小计购物车变量 php WooCommerce

Woocommerce 从结帐小计中排除税款

Woocommerce 如何使用 jquery 在“购物车小计”中获取值

在 Woocommerce 中根据 IP 地址(GeoLocation)更改添加到购物车按钮

禁用 Woocommerce 购物车订单项数量价格计算

WooCommerce 结帐单选按钮,可根据特定项目小计设置百分比费用