Hide Address Fields for WooCommerce

What is the main use that store owners make of the plugin?
Hiding the address fields when the customer choose local pickup and payment by cash.

How to never hide the address fields for purchase above some amount?
Update the amount:

add_filter( 'haf_hide_address', 'haf_dont_hide_address' );
function haf_dont_hide_address( $hide_enabled ) {
	$total = 100;
	return $total <= WC()->cart->get_cart_contents_total() ? false : $hide_enabled;

How to make the postcode field optional for some country?
You can use the haf_optional_postcode_countries filter. Keep in mind that the built-in WooCommerce postcode validation will not be applied when using the plugin and tax classes should not be restricted by postcodes.

What is the best practice for WooCommerce settings?
Enable the Default Customer Address option and disable the ‘Enable the shipping calculator on the cart page’ and ‘Hide shipping costs until an address is entered’ options.

How to hide the state field as well (not fully supported)?
Update the state value with valid one to the store country (orders will get this value, not compatible with international stores, shipping zones and tax classes should not be restricted by states):

add_action( 'haf_before_conditions', 'haf_hide_field' );
function haf_hide_field() { ?>
	<script type="text/javascript">
	jQuery( function( $ ) {
		$( document ).on( 'methods_matched', function() {
			$( '#billing_state_field' ).removeClass( 'validate-required woocommerce-validated' ).hide();
			$( '#billing_state' ).val( 'CA' );
		} );
	} );
<?php }

Leave a comment

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