Support » Plugin: WooCommerce » Flatrate shipping and free shipping both viewed

  • I have a woocommerce shop (in progress) with a flat rate and free shipping. Free shipping is valid when customer ads more then 50 euro of articles.

    If this is the case still the flat rate and the free shipping are available to choose from. I would like to have not showing the flat rate in case free shipping is valid.

    Is this possible

    Regards,

    Bob

    http://wordpress.org/extend/plugins/woocommerce/

Viewing 13 replies - 1 through 13 (of 13 total)
  • +1

    Would like to see a solution to this as well

    // Hide standard shipping option when free shipping is available
    add_filter( 'woocommerce_available_shipping_methods', 'hide_standard_shipping_when_free_is_available' , 10, 1 );
    
    /**
     *  Hide Standard Shipping option when free shipping is available
     *
     * @param array $available_methods
     */
    function hide_standard_shipping_when_free_is_available( $available_methods ) {
    
        if( isset( $available_methods['free_shipping'] ) AND isset( $available_methods['flat_rate'] ) ) {
    
            // remove standard shipping option
            unset( $available_methods['flat_rate'] );
        }
    
        return $available_methods;
    }

    add this to your themes functions.php file.

    @samueljeden

    GREAT, thanks a lot !!

    Regards,

    Bob

    Thanks!

    Exactly what I was looking for! Hope more people see this or WooComm should make this an option in the pluggin.

    Moses

    (@greenfuture)

    Very obvious issue !
    questions –
    1. if i add this code then when i update the theme the fix will be deleted ? if so should i create a child theme with css and functions.php
    2. where to add it with in the file.
    Thanks

    Well, fine, the code works, but not perfectly…

    After clicking the proceed button on checkout page zou get this red notification from Woocommerce; “Invalid shipping method.”

    Probably because there are no radio buttons or no dropdown…

    Please help! 🙂

    Hey,

    and further, if you adjust the cart (delete a few items to drop below the minimum amount), the free shipping option will stay there even if that is at the updated cart no longer valid 🙁

    Chirag Vora

    (@chirag740)

    Woothemes documentation suggests adding the following to functions.php:

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

    This will hide all other shipping methods, when free shipping is available. A very obvious thing to do for every store.

    willhearne

    (@willhearne)

    Thanks for the fix. It works perfectly! And you are right, this seems like a very obvious standard inclusion. Hopefully it will make it’s way in soon.

    Chirag Vora

    (@chirag740)

    You’re welcome.

    @willhearne

    In the code that I shared replace

    $available_methods[] = $freeshipping;

    with

    $available_methods['free_shipping'] = $freeshipping;

    otherwise you will encounter an error due to selection of wrong shipping method.

    Thanks for the heads up.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Flatrate shipping and free shipping both viewed’ is closed to new replies.