Make Postcode Checkout Field Required For Ireland In WooCommerce
In WooCommerce checkout page I'm looking to change the postcode field (Irish Eircode) to being a required field, by default this is an optional field when the selected country is Ireland. I just want to know is there a way to change this to required and to have a little red star beside the "Eircode" to signify that it is a required field.
The screenshot below should give a clear idea of what I mean:
Answer
For Ireland "postcode" field you need to alter the default WooCommerce country locale settings that are defined on WC_Countries
get_country_locale()
method as follow (on lines 950 to 958):
'IE' => array(
'postcode' => array(
'required' => false,
'label' => __( 'Eircode', 'woocommerce' ),
),
'state' => array(
'label' => __( 'County', 'woocommerce' ),
),
),
So using the following hooked function you can make the postcode
field required:
add_filter( 'woocommerce_get_country_locale', 'ireland_country_locale_change', 10, 1 );
function ireland_country_locale_change( $locale ) {
$locale['IE']['postcode']['required'] = true;
return $locale;
}
Code goes in functions.php file of your active child theme (active theme). Tested and works.
Similar answer: Make state checkout field required for a specific country in Woocommerce
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?