我使用Conditionally unset checkout field in woocommerce给出的条件结帐字段。 但是,它没有删除所需的验证字段? 如何在" if(true)"中传递条件语句?删除所需的验证? 换句话说,我该如何检查选择了哪个选项? 此致
if( true ){ // pass conditional statement here
unset($fields['billing']['add_house_name']); // remove field
$fields['billing']['add_building_name']['required'] = false; // remove required validation
}
return $fields;
答案 0 :(得分:1)
您可以使用以下代码覆盖结帐字段:
// Hook in
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
// Our hooked in function - $address_fields is passed via the filter!
function custom_override_default_address_fields( $address_fields ) {
$address_fields['address_1']['required'] = false;
return $address_fields;
}
您可以将此挂钩添加到您根据要触发验证来检查输入的条件。