简体   繁体   English

在 WooCommerce 中设置爱尔兰所需的邮政编码结帐字段

[英]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.

相关问题 Woocommerce结帐字段最大长度,仅输入数字字段(邮政编码) - Woocommerce checkout field maxlength, make input number field only (postcode) WooCommerce 结帐邮政编码字段顺序 - WooCommerce checkout postcode field order "如何在 WooCommerce 结帐中制作所需的表单字段" - How to make a form field required in WooCommerce checkout 为 WooCommerce 中的结帐邮政编码字段设置最大长度 - Set maxlength for checkout postcode field in WooCommerce 只有在Woocommerce结帐时未隐藏订单备注字段时才需要 - Make Order notes field required only when it is not hidden in Woocommerce checkout 如何在 WooCommerce 结账时根据国家/地区制作所需的自定义字段? - How to make a custom field required based on country on WooCommerce checkout? 在 WooCommerce 中为越南国家/地区设置所需的状态结帐字段 - Make state checkout field required for a Vietnam country in WooCommerce 根据送货方式在结帐字段中要求填写账单电话 - Woocommerce - Make Billing Phone required on Checkout Field Based on Shipping Method - Woocommerce 如何在 WooCommerce 结帐时根据多个国家/地区制作自定义字段? - How to make a custom field required based on multi countries on WooCommerce checkout? 使插件创建的自定义结帐必填字段在 WooCommerce 中可选 - Make custom checkout required field created by plugin optional in WooCommerce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM