WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Flatrate shipping and free shipping both viewed (14 posts)

  1. bob.mijwaard
    Member
    Posted 1 year ago #

    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/

  2. jenslund
    Member
    Posted 1 year ago #

    +1

    Would like to see a solution to this as well

  3. samueljeden
    Member
    Posted 1 year ago #

    // 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.

  4. bob.mijwaard
    Member
    Posted 1 year ago #

    @samueljeden

    GREAT, thanks a lot !!

    Regards,

    Bob

  5. jenslund
    Member
    Posted 1 year ago #

    Thanks!

  6. thecookiemonster
    Member
    Posted 1 year ago #

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

  7. greenfuture
    Member
    Posted 1 year ago #

    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

  8. vennett
    Member
    Posted 11 months ago #

    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! :)

  9. jasepo
    Member
    Posted 11 months ago #

    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 :(

  10. Chirag Vora
    Member
    Posted 9 months ago #

    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.

  11. willhearne
    Member
    Posted 9 months ago #

    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.

  12. Chirag Vora
    Member
    Posted 9 months ago #

    You're welcome.

  13. Chirag Vora
    Member
    Posted 9 months ago #

    @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.

  14. willhearne
    Member
    Posted 9 months ago #

    Thanks for the heads up.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic