[英]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.在 WooCommerce 结帐页面中,我希望将邮政编码字段(爱尔兰 Eircode)更改为必填字段,默认情况下,当所选国家/地区为爱尔兰时,这是一个可选字段。 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.
我只是想知道有没有办法将其更改为必填项,并在“Eircode”旁边有一个小红星表示它是必填字段。
The screenshot below should give a clear idea of what I mean:下面的屏幕截图应该清楚地说明我的意思:
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) :对于爱尔兰“邮政编码”字段,您需要更改在
WC_Countries
get_country_locale()
方法上定义的默认 WooCommerce 国家区域设置,如下所示(在第 950 到 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:因此,使用以下挂钩 function 您可以将
postcode
字段设为必需:
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).代码进入您的活动子主题(活动主题)的functions.php文件。 Tested and works.
测试和工作。
Similar answer: Make state checkout field required for a specific country in Woocommerce类似的答案: 在 Woocommerce 中为特定国家/地区制作所需的 state 结帐字段
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.