Hide Address Fields for WooCommerce


How to hide the billing address fields on checkout when the customer choose local pickup and pay by cash?
In the plugin settings choose ‘Local pickup’ in the ‘Shipping Methods’ option and ‘Cash on delivery’ in the ‘Payment Methods’ option.

How to hide some custom field on checkout as well?
Update the field id:

add_action( 'haf_before_conditions', 'haf_hide_custom_checkout_field' );
function haf_hide_custom_checkout_field() {
	?>
	<script type="text/javascript">
	jQuery( function( $ ) {
		$( document ).on( 'methods_matched', function() {
			$( '#billing_district_field' ).hide();
			$( '#billing_district' ).val( 'none' );
		} );
		$( document ).on( 'methods_not_matched', function() {
			$( '#billing_district' ).val( '' );
			$( '#billing_district_field' ).show();
		} );
	} );
	</script>
	<?php
}

How to disable the hiding of the 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 disable the hiding of the fields if the customer fill certain field (the field must be above the address fields)?
Update the field id:

add_action( 'haf_before_conditions', 'haf_hide_custom_checkout_field' );
function haf_hide_custom_checkout_field() {
	?>
	<script type="text/javascript">
	jQuery( function( $ ) {
		$( '#billing_company_field' ).on( 'change', function() {
			$( document.body ).trigger( 'haf_hide_fields' );
		} );
		$( document.body ).on( 'should_hide_fields', function() {
			if ( $( '#billing_company' ).val() ) {
				return false;
			}
		} );
	} );
	</script>
	<?php
}

Leave a Reply

Your email address will not be published.