由于某些原因,“帐单邮寄地址”中的所有字段均标记为可选-客户将帐单邮寄地址字段保留为空白,然后拒绝付款(由我们的付款处理方Square).
我找不到任何地方使这些字段为必填项,也无法弄清楚为什么在任何情况下都将其标记为可选字段.
有人可以指出我正确的方向吗?
更新
我什至尝试了以下方法:
add_filter('woocommerce_billing_fields', 'force_billing_fields', 1000, 1);
function force_billing_fields($fields) {
$fields['billing_first_name']['required'] = true;
$fields['billing_last_name']['required'] = true;
$fields['billing_address_1']['required'] = true;
$fields['billing_city']['required'] = true;
$fields['billing_postcode']['required'] = true;
$fields['billing_country']['required'] = true;
$fields['billing_state']['required'] = true;
$fields['billing_email']['required'] = true;
$fields['billing_phone']['required'] = true;
return $fields;
}
并且它们仍被标记为可选,除了计费电话和国家/地区现在已标记为必填项.但是其余的仍然是可选的.
解决方法:
如果您没有按照我的注释中的解释找到罪名,该怎么做是使用以下命令(如果某些其他代码已经在使用这些钩子,则在此处使用最高钩子优先级):
add_filter( 'woocommerce_default_address_fields', 'customising_checkout_fields', 1000, 1 );
function customising_checkout_fields( $address_fields ) {
$address_fields['first_name']['required'] = true;
$address_fields['last_name']['required'] = true;
$address_fields['company']['required'] = true;
$address_fields['country']['required'] = true;
$address_fields['city']['required'] = true;
$address_fields['state']['required'] = true;
$address_fields['postcode']['required'] = true;
return $address_fields;
}
代码进入您的活动子主题(或活动主题)的function.php文件中.测试和工作.
对于计费电话和电子邮件,您可以尝试
add_filter('woocommerce_billing_fields', 'custom_billing_fields', 1000, 1);
function custom_billing_fields( $fields ) {
$fields['billing_email']['required'] = true;
$fields['billing_phone']['required'] = true;
return $fields;
}
要么
add_filter('woocommerce_checkout_fields', 'custom_billing_fields', 1000, 1);
function custom_billing_fields( $fields ) {
$fields['billing']['billing_email']['required'] = true;
$fields['billing']['billing_phone']['required'] = true;
return $fields;
}