Restrict Shipping by Postcode in WooCommerce
In this tutorial, I will show you three methods of how you can configure ZIP/postcode-based shipping in WordPress (or, to be more specific, in your WooCommerce store).
- The first way involves creating a custom shipping zone.
- The second way allows you to leave your WooCommerce store shipping settings untouched, but at the same time to enable or disable specific shipping methods by a postcode(s) with the help of a custom plugin.
- The third approach will be a programmatic one.
Now, let’s dive into it.
Get Shipping Class ID or Slug
In this tutorial I would like to show you how you can either find both shipping class ID and slug in WordPress admin or get them programmatically using WC_Product object’s methods.
Billing and Shipping Address Fields
There are two type of fields in WooCommerce – billing and shipping fields (sorry for being so obvious). Some of the fields are presented in both of these categories, like a first name field or a country field. Some – may be presented in one of the categories only, like phone or email.
And now read carefully:
- We can make changes in the fields using hook
woocommerce_default_address_fields– in this case the changes will affect everything – both edit billing and shipping fields pages in “My account” and the Checkout page as well. woocommerce_shipping_fields– the same, but affects only shipping fieldswoocommerce_billing_fields– the same, but affects only billing fieldswoocommerce_checkout_fields– affects only the checkout page, nothing else, this hook is already described in details in a separate tutorial.