Wordpress woocommerce - 免费送货时隐藏统一费率

Wordpress woocommerce - hide flat rate when free shipping

我有一个 wordpress/woocommerce 网站。当用户购物车数量超过 500 时,我必须在购物车小计中免运费。现在我已经设置统一费率 25,如果数量超过 500,则免费送货。

我从帮助中 google 它并添加了一些代码到 functions.php 但仍然有同样的问题。

    function hide_all_shipping_when_free_is_available( $available_methods ) {

if( isset( $available_methods['free_shipping'] ) ) :

// Get Free Shipping array into a new array
$freeshipping = array();
$freeshipping = $available_methods['free_shipping'];

// Empty the $available_methods array
unset( $available_methods );

// Add Free Shipping back into $avaialble_methods
$available_methods = array();
$available_methods['free_shipping'] = $freeshipping;

endif;

return $available_methods;
}

我在 Oxygen 主题上使用 wordpress 和 woocommerce 2.3.8。

此致

你用的是老方法,我想你需要用这个new one

从 WooThemes 网站复制:

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;
}