根据购物车金额仅显示一个运费

时间:2017-07-07 11:19:08

标签: php wordpress woocommerce cart shipping

在WordPress中使用Woocommerce
我正试图找到一种方法来使用2个运费:
如果客户订单少于n金额,则运输是标准x金额
如果客户订单超过n金额,则运费减少到x金额
如果订单有资格减少运输,我还需要隐藏标准。

目前,如果订单有资格减少运费,那么woocommerce会显示运费

我有什么想法可以解决这个问题吗?

由于

1 个答案:

答案 0 :(得分:0)

这是一个附加在 woocommerce_package_rates 动作挂钩中的自定义功能,根据购物车金额限制仅显示一个运费:

add_filter( 'woocommerce_package_rates', 'hide_sshipping_rate_based_on_cart_amount', 100 );
function hide_sshipping_rate_based_on_cart_amount( $rates ) {

    // HERE define the limit amount to switch of shipping rate (integer)
    $amout_limit = 600;
    // Cart total amount (integer)
    $cart_total = WC()->cart->cart_contents_total;

    // Set below your 2 Rate ID slugs
    if( $cart_total >= $amout_limit )
        unset( $rates['flat_rate:12'] ); // Removes the LOWER Rate 
    else
        unset( $rates['flat_rate:8'] ); // Removes the HIGHER Rate

    return $rates;
}

代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中。

相关问题