Support » Plugin: WooCommerce » Hide all other shipping method when free shipping is available

  • Hi All,

    I just upgraded WC to 2.2.2 and I’m trying to enable shipping during checkout.

    I intend to have free shipping when amount hit $500 and above otherwise a flat rate will be imposed or customer can choose local pickup

    This works fine, whenever the amount hit $500 and above, the free shipping shows up, but the other 2 options (local pickup and flat rates still shows up)

    I came across a tutorial on add a function code in the template function file (functions.php) but it did not work.

    Does anyone has this working in WC (2.2.2)?

    any help would be great.

    Thank you in advanced.

    https://wordpress.org/plugins/woocommerce/

Viewing 1 replies (of 1 total)
  • hi steathtunnel

    I use a code snippet provided by Remi. It works great for me.

    // Hide ALL shipping options when free shipping is available
    add_filter( ‘woocommerce_available_shipping_methods’, ‘hide_all_shipping_when_free_is_available’ , 10, 1 );

    /**
    * Hide ALL Shipping option when free shipping is available
    *
    * @param array $available_methods
    */
    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[] = $freeshipping;

    endif;
    return $available_methods;
    }

    mitmak

Viewing 1 replies (of 1 total)
  • The topic ‘Hide all other shipping method when free shipping is available’ is closed to new replies.