我已经按照以下方法使用该方法使结帐字段可选。但是,我发现当非登录用户提交订单时,填写地址字段的警报会跳出来。
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
function custom_override_default_address_fields($address_fields) {
$address_fields['first_name']['required'] = false;
$address_fields['last_name']['required'] = false;
$address_fields['address_1']['required'] = false;
$address_fields['address_1']['placeholder'] = '';
$address_fields['address_2']['required'] = false;
$address_fields['address_2']['placeholder'] = '';
$address_fields['postcode']['required'] = false;
$address_fields['city']['required'] = false;
return $address_fields;
}
顺便说一下,我还尝试将结算和发货字段作为链接WooCommerce: Disabling checkout fields with a filter hook中的方法单独选择。
答案 0 :(得分:0)
转到该线程Make checkout fields required in Woocommerce checkout,对于不需要的字段,将true更改为false 例如:change $ address_fields ['postcode'] ['required'] = true; 到$ address_fields ['postcode'] ['required'] = false;
答案 1 :(得分:0)
取决于要使哪些结帐字段为可选(或必填)的字段,您需要将其绑定到两个过滤器中。第一个过滤器是woocommerce_default_address_fields
,用于地址字段,第二个过滤器是woocommerce_billing_fields
,用于billing_phone
和billing_email
字段。
add_filter( 'woocommerce_default_address_fields', 'adjust_requirement_of_checkout_address_fields' );
function adjust_requirement_of_checkout_address_fields( $fields ) {
$fields['first_name']['required'] = false;
$fields['last_name']['required'] = false;
$fields['company']['required'] = false;
$fields['country']['required'] = false;
$fields['address_1']['required'] = false;
$fields['address_2']['required'] = false;
$fields['city']['required'] = false;
$fields['state']['required'] = false;
$fields['postcode']['required'] = false;
return $fields;
}
add_filter( 'woocommerce_billing_fields', 'adjust_requirement_of_checkout_contact_fields');
function adjust_requirement_of_checkout_contact_fields( $fields ) {
$fields['billing_phone']['required'] = false;
$fields['billing_email']['required'] = false;
return $fields;
}