更新时间:2023-11-30 11:41:16
如果你没有像我的评论中解释的那样发现有罪,你可以做的是使用以下(在此处使用最高挂钩优先级,如果其他一些代码已经在使用这些钩子):
What you can do if you don't find the guilty as explained on my comment is to use the following (using here a highest hook priority if some other code is already using those hooks):
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 文件中.经测试有效.
Code goes in function.php file of your active child theme (or active theme). tested and works.
对于计费电话和电子邮件,您可以尝试
For billing phone and email you can try
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;
}