• Hi everyone, can someone please give me a hand with the following? I would like to alter the following code so that flat_rate:17 is also included in the list when free shipping is available.

    /**
    * 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;
    $free_shipping = true;
    }
    if ( $free_shipping == true && 'local_pickup:21' === $rate->id ) {
    $free[ $rate_id ] = $rate;
    }

    }
    return ! empty( $free ) ? $free : $rates;
    }
    add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    As a guess, try adding this right below the current if(){} structure in bold:

    if ( $free_shipping == true && 'flat_rate:17' === $rate->id ) {
    $free[ $rate_id ] = $rate;
    }

    If that doesn’t do it, you should probably ask the experts in the plugin’s dedicated support forum: https://www.ads-software.com/support/plugin/woocommerce/

    Thread Starter helencham

    (@helencham)

    Hi @bcworkz, but i need to have all three available.

    Eg,

    if ( $free_shipping == true && ‘flat_rate:17’ && ‘local_pickup:21’ === $rate->id ) {
    $free[ $rate_id ] = $rate;
    }

    But i’m just not sure if that is how the code should be coded.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Make shipping option always available even when free shipping is provided’ is closed to new replies.