微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – WooCommerce – 免费送货时隐藏其他送货方式

我想在Woocommerce上免费送货时隐藏其他送货选项.

因为即使有免费送货选项,最新版本的woocommerce现在仍然显示其他送货选项.

请帮忙

解决方法:

最近有一个WooCommerce 2.6的代码片段.你可以尝试:

add_filter( 'woocommerce_package_rates', 'hide_other_shipping_when_free_is_available', 100, 2 );

function hide_other_shipping_when_free_is_available( $rates, $package ) {

    $free = array();
    foreach ( $rates as $rate_id => $rate ) {
        if ( 'free_shipping' === $rate->method_id ) {
            $free[ $rate_id ] = $rate;
            break;
        }
    }
    return ! empty( $free ) ? $free : $rates;
}

You will need to refresh shipping cached data: disable, save and enable, save related shipping methods for the current shipping zone, in woocommerce shipping settings.

对于WooCommerce 2.5,你应该试试这个:

add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );

function hide_shipping_when_free_is_available( $rates, $package ) {

    // Only modify rates if free_shipping is present
    if ( isset( $rates['free_shipping'] ) ) {

        // To unset a single rate/method, do the following. This example unsets flat_rate shipping
        unset( $rates['flat_rate'] );

        // To unset all methods except for free_shipping, do the following
        $free_shipping          = $rates['free_shipping'];
        $rates                  = array();
        $rates['free_shipping'] = $free_shipping;
    }

    return $rates;
}

将此代码粘贴到位于活动子主题主题中的function.PHP文件中.

参考:

> Hide other shipping methods when FREE SHIPPING is available (official doc)
> WooCommerce Free Shipping if over 5 pounds

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐