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 other custom fields on checkout as well?
Update the fields id:

add_action( 'haf_before_conditions', 'haf_hide_custom_checkout_fields' );
function haf_hide_custom_checkout_fields() {
	?>
	<script type="text/javascript">
	jQuery( function( $ ) {
		var nn = 'none', field1_val = '', field2_val = '', field3_val = '', field1 = 'billing_floor', field2 = 'billing_entrance', field3 = 'billing_housenumber';
		$( document ).on( 'methods_matched', function() {
			$( '#' + field1 + '_field' ).hide();
			if ( $( '#' + field1 ).val() != nn ) {
				field1_val = $( '#' + field1 ).val();
				$( '#' + field1 ).val( nn );
			}
			$( '#' + field2 + '_field' ).hide();
			if ( $( '#' + field2 ).val() != nn ) {
				field2_val = $( '#' + field2 ).val();
				$( '#' + field2 ).val( nn );
			}
			$( '#' + field3 + '_field' ).hide();
			if ( $( '#' + field3 ).val() != nn ) {
				field3_val = $( '#' + field3 ).val();
				$( '#' + field3 ).val( nn );
			}				
		} );
		$( document ).on( 'methods_not_matched', function() {
			if ( $( '#' + field1 ).val() == nn ) {
				$( '#' + field1 ).val( field1_val );
			}
			$( '#' + field1 + '_field' ).show();
			if ( $( '#' + field2 ).val() == nn ) {
				$( '#' + field2 ).val( field2_val );
			}
			$( '#' + field2 + '_field' ).show();
			if ( $( '#' + field3 ).val() == nn ) {
				$( '#' + field3 ).val( field3_val );
			}
			$( '#' + field3 + '_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. Required fields are marked *