使Woocommerce结帐状态字段为必填项 [英] Make Woocommerce checkout state field required
问题描述
所以这个问题可能有一个简单的解决方案,但是我暂时还停留在此.在最后一次更新(Woocommerce 3.3.5)之后,我对结帐页面上的状态字段有问题,因为它不是强制性的,人们只是跳过了它.我确实需要强制执行此操作,因为我已通过API将API的网站直接连接到送货公司服务器,并将网站连接到送货公司服务器.
So this problem may have a easy solution, but I'm stuck for the moment. After the last update (Woocommerce 3.3.5) I have a problem with the state field on the checkout page, because it is not mandatory and people just skip it. I really need this thing to be mandatory, because I have connected my website to the delivery company server through and API to send the order info directly to them.
我尝试将其添加到我的functions.php中,事实是,当我转到结帐页面时,该字段带有一个星号,但仅需一秒钟.
I tried adding this to my functions.php and the thing is that when I go to the checkout page, the field has an asterisk, but for like one second.
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;
}
感谢您的帮助.谢谢!
推荐答案
在上一个woocommerce版本3.3.5中,默认情况下,必填状态字段…因此,在您的情况下,该字段为不"必需.
By default in Last woocommerce version 3.3.5, state field is required… So in your case something is making that field "not" required.
您可以尝试以下(同时处理帐单和送货字段):
add_filter( 'woocommerce_default_address_fields' , 'make_state_field_required', 90, 1 );
function make_state_field_required( $address_fields ) {
$address_fields['state']['required'] = true;
return $address_fields;
}
代码进入您的活动子主题(或活动主题)的function.php文件中.可以.
Code goes in function.php file of your active child theme (or active theme). It could works.
这篇关于使Woocommerce结帐状态字段为必填项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!