What can we help you with?

How to avoid Address Validation when certain Shipping Method is selected? (Code Snippet)

Chris has a WooCommerce store in which he uses ELEX WooCommerce Address Validation & Address Autocomplete Plugin. He has a custom requirement in which he wants to avoid address validation when a certain shipping method is selected. Which means when a customer selects a specific shipping method, his/her address will not be validated and the order is placed right away.

If you have a similar requirement, follow the below method.

Avoiding Address Validation for Certain Shipping Method

Consider a scenario where you want to avoid address validation for Local Pickup shipping method.

Add the following code snippet in the Theme Functions (functions.php) file of your active website theme.

function xa_exclude_addr_validation() {
	if(isset($_POST['shipping_method']) && (explode(':',$_POST['shipping_method'][0])[0]) == 'local_pickup') { //change local_pickup to desired WooCommerce shipping method
	else if(isset($_POST['shipping_method'])) {
	$exclude_validation = get_option('exclude_addr_val');
	if($exclude_validation) {
		return true;

When the above code snippet is added, the plugin avoids address validation whenever WooCommerce default shipping method Local Pickup (local_pickup) is selected. Hence whenever local pickup is selected by your customers, their order is placed directly without address validation.


To explore more details about the plugin, go check out ELEX WooCommerce Address Validation & Address Autocomplete Plugin.

or read the product documentation to know every feature of the plugin, in detail.

You can also check out other WooCommerce and WordPress plugins in ELEX.

You must be logged in to post a comment.