A client asked me why WooCommerce shows different shipping methods that are activated when free shipping is available? In this client’s example the free shipping options is only active when the order amount is $50 or more.
In the screenshot below, example one is the default WooCommerce setting. However, example two is how the client prefers it. This can be achieved by adding a piece of code to your theme functions.php.
WooCommerce must have had a good reason to default the first example. But, in my client’s webshop it looked really weird. Why should a buyer select a flat rate of $6.75 when he or she can use Free Shipping?
You may wanna clear this confusion. To do that, just copy the following chunk of code and place it directly in your theme’s functions.php. You’re all done!
Jeff Druce says
Hello Frank,
I found your code while searching for a solution to hide select shipping methods when free shipping is activated. I can’t seem to get it to work.
The client is using WooCommerce 2.3.11 and EasyPost. Their default ground service is USPS Priority Mail. That’s the only option I want to disable. That way, users can still opt to pay for an expedited shipping option. I’m trying to fool-proof shipping options – a customer has already selected Priority Mail when they were eleigible for free shipping.
I can usually follow the logic of php, but I’m far from experienced.
From your code above I changed “flat_rate” to “Priority” (line 19).
Additionally, I commented out lines 22-24. Even tried deleting lines 21-24.
As far as I know, “Priority” is the right variable name – I tested a lower case “p” as well.
In any event, when free shipping kicks in, the USPS Priority Mail option still shows on the cart page and the checkout page. Any suggestions would be appreciated.
Here’s the code I installed:
**
* woocommerce_package_rates is a 2.1+ hook
*/
add_filter( ‘woocommerce_package_rates’, ‘hide_shipping_when_free_is_available’, 10, 2 );
/**
* Hide shipping rates when free shipping is available
*
* @param array $rates Array of rates found for the package
* @param array $package The package array/object being shipped
* @return array of modified rates
*/
function hide_shipping_when_free_is_available( $rates, $package ) {
// Only modify rates if free_shipping is present
if ( isset( $rates[‘free_shipping’] ) ) {
// To unset a single rate/method, do the following. This example unsets flat_rate shipping
unset( $rates[‘Priority’] );
}
return $rates;
}
frank says
Hi Jeff,
The USPS Shipping method is added with a plugin from WooCommerce? Then have al look at this article: http://docs.woothemes.com/document/usps-shipping/. At the bottom of the article there is a snippet on how to exclude a country by country code. I guess this will be a good start.
Good Luck, Frank
Rabeya says
Hello Frank,
How can I disable total shipping method for a particular role of a user.
Like, I do not want to show shipping method in cart or checkout page when a wholesale customer log in. it is not free shipping, In my setup a wholesale customer can place order through cheque gateway. then I will send an invoice with shipping cost and payment details. but it is not applicable for retail customer.
Can you suggest me any solution?? It will be really helpful.
wordpress 4.6
woocommerce 2.6.4
Frank Schrijvers says
Hey Abeya,
I think the solution you are looking for depends on the plugin you use for the wholesale solution. An example of what you might be looking for can be found here: http://stackoverflow.com/questions/17674031/is-there-a-function-for-knowing-if-user-is-shop-manager-in-wp-woocommerce