問題描述
出于某種原因,帳單地址中的所有字段都標記為可選 - 客戶將帳單地址字段留空,然后他們的付款被拒絕(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;
}
它們仍然被標記為可選,除了帳單電話和國家/地區(qū)現在被標記為必需.但其余的仍然是可選的.
And they're still marked as optional, except the billing phone and country are now marked as required. But the rest are still optional.
推薦答案
如果你沒有像我的評論中解釋的那樣發(fā)現有罪,你可以做的是使用以下(在此處使用最高掛鉤優(yōu)先級,如果其他一些代碼已經在使用這些鉤子):
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 結帳中的結帳字段成為必需的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!