• Resolved rumpelstilzchen94

    (@rumpelstilzchen94)


    I would like to hide all other shipping methods when Free Shipping becomes available for each shipping zone.

    I tried the plugin WC Hide Shipping Methods and the code found on the official Woocommerce website but somehow it doesn’t work with the shipping zones.

    /**
     * Hide shipping rates when free shipping is available.
     * Updated to support WooCommerce 2.6 Shipping Zones.
     *
     * @param array $rates Array of rates found for the package.
     * @return array
     */
    function my_hide_shipping_when_free_is_available( $rates ) {
        $free = array();
        foreach ( $rates as $rate_id => $rate ) {
            if ( 'free_shipping' === $rate->method_id ) {
                $free[ $rate_id ] = $rate;
                break;
            }
        }
        return ! empty( $free ) ? $free : $rates;
    }
    add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );

    Each shipping zone has its own minimum order amount to activate free shipping. Italy 99€, Germany 120€ and Rest of the World 140€.

    Problem: when a customer places an order and the order amount is 99€ he will get free shipping, no matter what country is selected…

Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Hide all shipping methods when Free shipping is available’ is closed to new replies.