Make checkout fields required in Woocommerce checkout(使 Woocommerce 结帐中的结帐字段成为必需)
问题描述
出于某种原因,帐单地址中的所有字段都标记为可选 - 客户将帐单地址字段留空,然后他们的付款被拒绝(Square,我们的付款处理方).
For some reason, all the fields in Billing Address are marked as optional - customers are leaving the billing address fields blank and then their payments are being rejected (by Square, who is our payment processor).
我找不到任何地方将这些字段设为必填字段,也无法弄清楚为什么它们在任何情况下都会被标记为可选.
I cannot find anywhere to make these fields required, and cannot figure out why they would be marked as optional in any case.
有人能指出我正确的方向吗?
Can someone point me in the right direction?
更新
我什至尝试过以下方法:
I've even tried the following:
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;
}
它们仍然被标记为可选,除了帐单电话和国家/地区现在被标记为必需.但其余的仍然是可选的.
And they're still marked as optional, except the billing phone and country are now marked as required. But the rest are still optional.
推荐答案
如果你没有像我的评论中解释的那样发现有罪,你可以做的是使用以下(在此处使用最高挂钩优先级,如果其他一些代码已经在使用这些钩子):
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;
}
这篇关于使 Woocommerce 结帐中的结帐字段成为必需的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使 Woocommerce 结帐中的结帐字段成为必需
基础教程推荐
- 在多维数组中查找最大值 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01