Posted on

WooCommerce: How to Hide “Shipping Calculator” Fields @ Cart

The “Shipping Calculator” can be enabled via the WooCommerce settings in order to give the user a way to calculate their shipping fees before getting to the Checkout Page. Usually they fill out the country, state, city and postcode form fields and click on “Update Totals” in order to calculate the shipping.

However, what if you only calculate shipping based on country? Or what if you only charge by zip code / postcode? In this case, you will need to hide the input fields you don’t need, and make UX better.

Well, here are some WooCommerce filters you can use from WooCommerce version 3.4 onwards to hide the fields you like (apart from country, which is mandatory).

WooCommerce: how to hide shipping calculator input fields

PHP Snippet: Hide “Shipping Calculator” Fields @ WooCommerce Cart


/**
* @snippet 	Hide "Shipping Calculator" Fields @ WooCommerce Cart
* @how-to 	Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode 	https://businessbloomer.com/?p=74646
* @author 	Rodolfo Melogli
* @testedwith 	WooCommerce 3.4.2
*/

// 1 Disable State
add_filter( 'woocommerce_shipping_calculator_enable_state', '__return_false' );

// 2 Disable City
add_filter( 'woocommerce_shipping_calculator_enable_city', '__return_false' );

// 3 Disable Postcode
add_filter( 'woocommerce_shipping_calculator_enable_postcode', '__return_false' );

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

Does this snippet still work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert, WordCamp speaker and Internet marketer, Rodolfo Melogli has worked as a WooCommerce freelancer since 2011. He helps entrepreneurs and developers overcome their WooCommerce nightmares :) Rodolfo is the organiser of WordCamp Dublin, the Dublin WooCommerce Meetup, the Dublin Ecommerce Meetup and the Dublin WordPress Meetup. He enjoys interacting with people, travelling and chasing tennis & soccer balls. Of course, he loves pizza too.

8 thoughts on “WooCommerce: How to Hide “Shipping Calculator” Fields @ Cart

  1. Hi. I only ship in the US. I have a flat rate and free shipping if order is over a $ value. I have this working great. How can I show shipping cost on the Cart page without needing the address input (as it isn’t needed for my shipping methods)? Woo seems to calculate this shipping without an address because the Checkout page has the shipping calculated properly without an address. I tried setting Default Customer Location to Store Location but that added sales tax for my store location as well. Thank you!

    1. Hey Tania, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  2. Worked perfectly thanks. However, I am also one who only ships to the to US locations and so it seems odd to customers to have to click US, especially when it is easy to not have to have that as a required field on the checkout page using a plugin.

    Someone need to develop a plugin to set the country field on the cart page to a particular country and have that automatically hide the country field.

    1. Good thinking John – thanks so much for your comment! Maybe you want to suggest that to Woo developers here: https://github.com/woocommerce/woocommerce/issues > new issue

  3. Hi,
    My shipping is local and charges are based on the zip-code, so I wanted to hide the country and state fields, as these will always be the same. The problem is, when I do it, the shipping calculation doesn’t work for new clients, probably because woocommerce needs to know the country and maybe state too to do it correctly. Is it possible to set the relevant variables and then hide the fields?

    1. Hello Dimitris, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  4. Thanks!
    Is it possible to hide the block Shipping itself (IE shipping, IE fast shipping, etc. in your example) on the cart page?
    Shipping will be calculated, depending on postcode filled in on the checkout page. I’d like to have shipping details on checkout page only.

    1. Hey Mieke, thanks so much for your comment! You should be able to hide shipping costs from the WooCommerce settings ๐Ÿ™‚

Questions? Feedback? Support? Leave your Comment Now!
If you're writing code, please wrap it between: [php] code_here [/php]

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.