Skip to content

Instantly share code, notes, and snippets.

@rynaldos-zz
Last active July 2, 2020 05:20
Show Gist options
  • Select an option

  • Save rynaldos-zz/2968dd1875c86298381eb28c4cd9444d to your computer and use it in GitHub Desktop.

Select an option

Save rynaldos-zz/2968dd1875c86298381eb28c4cd9444d to your computer and use it in GitHub Desktop.
[WooCommerce 3.0] make NZ region compulsory in checkout page
add_filter( 'woocommerce_billing_fields', 'woo_filter_state_billing', 10, 1 );
add_filter( 'woocommerce_shipping_fields', 'woo_filter_state_shipping', 10, 1 );
function woo_filter_state_billing( $address_fields ) {
$address_fields['billing_state']['required'] = true;
return $address_fields;
}
function woo_filter_state_shipping( $address_fields ) {
$address_fields['shipping_state']['required'] = true;
return $address_fields;
}
//Did this help? Donate me some BTC: 1BEsm8VMkYhSFJ92cvUYwxCtsfsB2rBfiG
@hheal
Copy link
Copy Markdown

hheal commented Jul 23, 2018

Hi - just trying to apply this now (to functions.php?) - and it doesn't seem to be working. Have you made any edits to this recently to keep it current?
Need region to be compulsory for shipping calculations to work properly...
Thanks

@ThornedRose
Copy link
Copy Markdown

//Make Region (State) required
function custom_nz_locale($locale){
  $locale['NZ']['state']['required'] = true;
  return $locale;
}
add_filter('woocommerce_get_country_locale', 'custom_nz_locale');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment