Patrick's Programming Blog

Only Ship to Continental United States with WooCommerce

  1. Blogging for Benjamin Competition
  2. Why I'm Grateful to Work on the Web
  3. 24 Pull Requests
  4. Update Downloadable Product's Expiration Date in WooCommere
  5. Get Lost in the Flow and Work for More Than a Salary
  6. Why A Plugin's Popularity Matters
  7. Why You Should (Or Shouldn't) Use Premium Plugins
  8. WooCommerce Terms & Conditions
  9. Only Ship to Continental United States with WooCommerce
  10. Just Talk
  11. Why I Love Jetpack
  12. Making Jetpack Better
  13. Remove Billing Address for Free Virtual Orders in WooCommerce
  14. Notify Admin of Customer Address Change in WooCommerce
  15. Open Your Self Up To New Possibilities
  16. 2013 Resolutions Review
  17. Create a Community
  18. Tips for Starting a Community
  19. The Intent of Goals
  20. Create The Ultimate Invoicing System Using WooCommerce
  21. Change From Address in Ninja Forms
  22. Work With People Who Inspire You
  23. Contact Form 7 & MailPoet Integration
  24. Monotasking
  25. Giving Back to The Community
  26. Adding Fuctionality to Lean Plugins
  27. Choose Stripe For a Payment Gateway
  28. A Dip Into Entrepreneurship
  29. Reward Yourself
  30. Blogging for Benjamin Plugin
  31. Blogging for Benjamin Wrap Up

One of the most powerful plugins for WooCommerce is Table Rate Shipping because it's so configurable. You can create your own rules for bulk shipping, weight based shipping, or set up shipping zones and charge different rates for each zone. When someone requests their existing shipping method only support certain zones, or charge extra for specific zones we usually point them to Table Rate Shipping because that extension can do just about anything.

It would be nice if we could take some of the functionality of that plugin out and apply it to other shipping methods (like UPS, FedEx, USPS, etc.) but at WooThemes we're very aware of feature creep and if we added these other feature the existing shipping methods would be bloated to the point of being unusable. So without adding a whole bunch of options that most users don't want the best way to do this is to write a snippet of code to do this.

Only Ship to Continental United States

I decided to dig in and create a mini plugin for users to which checks which state they are in and then disables all shipping methods if the user isn't in the continental United States. I'm including the plugin for you to look at the code but you can also go the plugins home page and download it, extract the zip file, and upload the folder to your /wp-content/plugins/ directory of your site.

Shipping Hooks

I've been doing support for WooCommerce for just about 6 months now and it's still amazing to me how easy it is to change something using the giant list of hooks we have. For shipping methods especially there's the woocommerce_available_shipping_methods filter you can use to do modify them however you need.

Hopefully this plugin solves whatever needs you have and if not use that woocommerce_available_shipping_methods hook and happy coding! 🙂

Exit mobile version