Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hide default flat rate shipping method when free shipping is available
// 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;
}
@sykesflo

This comment has been minimized.

Copy link

@sykesflo sykesflo commented Jul 12, 2013

Hello!

Where do you put this code? In what file?
Sorry, I'm a newbie.
Thanks!

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jan 21, 2014

In your themes or child themes functions.php would suffice

@kamleshpawar2006

This comment has been minimized.

Copy link

@kamleshpawar2006 kamleshpawar2006 commented Feb 3, 2014

i pasted this code in my themes functions.php but 'Calculate Shipping ↓' is still there in cart page.how to remove it from there?

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jul 4, 2014

Same issue here. What's wrong?

@bekarice

This comment has been minimized.

Copy link

@bekarice bekarice commented Jul 11, 2014

There's a setting under WooCommerce > Shipping to enable the shipping calculator on the cart page. Disable that setting to do so.

@tatof

This comment has been minimized.

Copy link

@tatof tatof commented Jul 28, 2014

How can i make this posible for "local_delivery".

Got flat_rate as default and when "local_ delivery" is available I want to automatic choose that option and remove flat_rate.

Tryed this but doesn't work:

add_filter( 'woocommerce_available_shipping_methods', 'hide_standard_shipping_when_free_is_available' , 10, 1 );

function hide_standard_shipping_when_free_is_available( $available_methods ) {
if( isset( $available_methods['local_delivery'] ) AND isset( $available_methods['flat_rate'] ) ) {
// remove standard shipping option
unset( $available_methods['flat_rate'] );
}
return $available_methods;
}

@tarunagarwal11

This comment has been minimized.

Copy link

@tarunagarwal11 tarunagarwal11 commented Sep 25, 2014

Fantastic works fine...Thanks a ton maxrice...

@kiritDholakiya

This comment has been minimized.

Copy link

@kiritDholakiya kiritDholakiya commented Nov 13, 2014

add_filter( 'woocommerce_package_rates', 'custom_shipping_by_product_weight',10,2);
function custom_shipping_by_product_weight($rates,$packages){
echo print_r( $rates, 1 );
wp_die();
}

=> I added above code in functions.php file but nothing happen. i want to know all available methods. and only set ups method for cart weight greater than 2lbs and set USPS method for less than 2 lbs.

Please help me to sort out this problem.
Thanks...

@alemarengo

This comment has been minimized.

Copy link

@alemarengo alemarengo commented Mar 29, 2015

There's another gist (https://gist.github.com/mikejolley/11171530) where some discussed about this issue. I cannot believe I don't understand why this method doesn't affect my ecommerce. I need only local_pickup and free_shipping. I need to hide flat_rate even it exists and should stay there. How can I fix this? I'd be glad to receive your help. :)

@dsyvon

This comment has been minimized.

Copy link

@dsyvon dsyvon commented Sep 29, 2017

i put the code in my child theme functions and disabled shipping calculator in woocommerce settings and yet the drop down menu of countries is there on the cart page along with shipping options. This has been a three hour problem that remains unresolved despite the amount of plugins and php I put in. H E L P

@CasperBraske

This comment has been minimized.

Copy link

@CasperBraske CasperBraske commented Mar 18, 2018

This filter has been deprecated a long time ago.

DON'T USE IT!

Refer here for alternative snippets.

woocommerce/woocommerce#4230

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment