Stop Checkout if Wrong Ship to State Entered
-
We cannot ship our products across state lines so have Zones 1 and 2 setup (both in the same state, but with different delivery prices based upon zip codes that we entered.)
If I try and checkout with an Oregon Address it says
No shipping options were found for Beaverton, OR 97005. Enter a different address
But allows me to continue to checkout, click either enter a CC or click PayPal and pay.
Is there a way to disable the ability to pay if people are NOT from Washington State?
-
We cannot ship our products across state lines so have Zones 1 and 2 setup (both in the same state, but with different delivery prices based upon zip codes that we entered.)
If I try and checkout with an Oregon Address it says. No shipping options were found for Beaverton, OR 97005. Enter a different address
But allows me to continue to checkout, click either enter a CC or click PayPal and pay. Is there a way to disable the ability to pay if people are NOT from Washington State?
From what I understand, you’re looking to limit your product shipping exclusively to Washington State, and you’re encountering issues when attempting a checkout with an address outside this zone. You’re also interested in disabling the payment option for customers not residing in Washington State.
You can easily manage this by setting your selling country restriction. Simply go to WooCommerce > Settings > General, and choose the Selling location(s) option. Here, you can specify that you only sell to customers in the United States.
Image Link: https://s11.gifyu.com/images/SgaVw.gif
Furthermore, to limit your selling state to only Washington, you can use the following code:
add_filter( 'woocommerce_states', 'bbloomer_sell_one_state' ); function bbloomer_sell_one_state( $states ) { // Only sell to United States > Washington $states['US'] = array('WA' => __( 'Washington', 'woocommerce' ),); return $states; }
You should add this code to your child theme’s
functions.php
file or via a plugin that allows custom functions to be added, like the Code Snippets plugin. Please note that it’s not advisable to add custom code directly to your parent theme’sfunctions.php
file. Doing so could lead to the code being erased when the theme is updated.?? Just a quick reminder: Before you make any changes, we strongly recommend that you create a backup of your full site and database. This is a crucial step to ensure that in case anything goes wrong, you can easily restore your site to its previous, functioning state.
Once you implement this code, it will override the default states in WooCommerce and only permit sales to Washington State. As a result, customers from other states or countries won’t be able to finalize their purchases.
Here’s a sample of how it will appear on the checkout page:
Image Link: https://snipboard.io/6gMprb.jpg
I hope this solution works for you! If you have any additional questions, please don’t hesitate to ask.
That you for the response. I don’t care who pays for the items, only where they are shipped (IE: shipping address)
We want people from anywhere to be able to pay for the items, we just need to limit where they are delivered/shipped.
I don’t care who pays for the items, only where they are shipped (IE: shipping address)
We want people from anywhere to be able to pay for the items, we just need to limit where they are delivered/shipped.
Thanks for reaching out! I get that you’re open to accepting payments from anywhere, but need to restrict the delivery of your items to specific locations, in this case, Washington State. Let’s get that sorted for you!
Firstly, adjust your ‘Shipping location(s)‘ settings in WooCommerce. Follow these steps:
- Head over to WooCommerce > Settings > General.
- Click ‘Shipping location(s)‘ and choose ‘Ship to specific countries only‘. Here, you can specify that you only ship to customers in the United States.
Image Link: https://snipboard.io/DhWm4o.jpg
To further narrow down your shipping to only Washington State, use the following code:
function bbloomer_only_ship_to_wa( $rates, $package ) { global $woocommerce; $excluded_states = array( 'AL' , 'AK', 'AZ', 'AR' , 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WV', 'WI', 'WY', 'AA', 'AE', 'AP' ); if( in_array( WC()->customer->get_shipping_state(), $excluded_states ) ) { $rates = array(); } return $rates; } add_filter( 'woocommerce_package_rates', 'bbloomer_only_ship_to_wa', 10, 2 );
You should add this code to your child theme’s
functions.php
file or via a plugin that allows custom functions to be added, like the Code Snippets plugin. Please note that it’s not advisable to add custom code directly to your parent theme’sfunctions.php
file. Doing so could lead to the code being erased when the theme is updated.Always back up your site before making changes.
I hope this helps! If you have any other questions or need further assistance, feel free to ask.
Thanks for this.
What happens if their billing address is from the wrong state and they uncheck the “Ship to a different address”?
Will the order be allowed to go forward or be stopped?
What happens if their billing address is from the wrong state and they uncheck the “Ship to a different address”?
Will the order be allowed to go forward or be stopped?
Thanks for your follow-up question. The code provided earlier only checks the shipping address, not the billing address. So, if a customer has a billing address outside of Washington State but chooses to ship to an address within Washington State, the order will proceed as normal.
However, if they uncheck the “Ship to a different address” box, the system will automatically use the billing address as the shipping address. If the billing address is outside of Washington State, the order will not proceed because the shipping address (which is now the same as the billing address) is not within the allowed shipping zone.
In other words, the order will only go forward if the shipping address is within Washington State, regardless of where the billing address is.
I hope this clarifies things for you. If you have further questions or need more assistance, feel free to let me know.
I put your code in.
If I have an address with the wrong state I get the warning about the shipping/delivery, but it allows me to click Pay with Paypal which pops up and it’s asking me to log in to my PayPal account.
It gives me a warning, but isn’t actually stopping me.
Is there a way to make it stop the ability to continue with the transaction?
- This reply was modified 1 year, 2 months ago by EnvisionDesign.
- This reply was modified 1 year, 2 months ago by EnvisionDesign.
I put your code in. If I have an address with the wrong state I get the warning about the shipping/delivery, but it allows me to click Pay with Paypal which pops up and it’s asking me to log in to my PayPal account. It gives me a warning, but isn’t actually stopping me. Is there a way to make it stop the ability to continue with the transaction?
Great question. The restriction based on the shipping address takes effect when you attempt to finalize the order. If the shipping address (which is the billing address when “Ship to a different address” is unchecked) is outside of Washington State, the system will not allow the order to be placed.
In the case of PayPal, you might be able to log into your account and proceed until the final review of your order. However, once you try to complete the order, it will fail if the shipping address is not within Washington State.
This is because the shipping address restriction is implemented at the WooCommerce level, not at the payment gateway level. So, while PayPal may initially allow you to proceed, the final order review within WooCommerce will prevent the order from being placed if the shipping address is not within the allowed zone.
Image Link: https://snipboard.io/WBlcTM.jpg
I hope this helps clarify the process. If you have any more questions or need further assistance, don’t hesitate to ask.
- The topic ‘Stop Checkout if Wrong Ship to State Entered’ is closed to new replies.