WordPress最新版woocommerce结算页面去掉其它表单字段
旧版本可以通过以下代码去掉:
add_filter('woocommerce_checkout_fields', 'ggdoc_woocommerce_checkout_fields', PHP_INT_MAX);
function ggdoc_woocommerce_checkout_fields($woo_checkout_fields_array)
{
// unset($woo_checkout_fields_array['billing']['billing_first_name']);
unset($woo_checkout_fields_array['billing']['billing_last_name']);
// unset($woo_checkout_fields_array['billing']['billing_phone']);
unset($woo_checkout_fields_array['billing']['billing_email']);
unset($woo_checkout_fields_array['order']['order_comments']); // remove order notes
unset($woo_checkout_fields_array['billing']['billing_company']); // remove company field
unset($woo_checkout_fields_array['billing']['billing_country']);
// unset( $woo_checkout_fields_array['billing']['billing_address_1'] );
// unset( $woo_checkout_fields_array['billing']['billing_address_2'] );
unset($woo_checkout_fields_array['billing']['billing_city']);
unset($woo_checkout_fields_array['billing']['billing_state']); // remove state field
unset($woo_checkout_fields_array['billing']['billing_postcode']); // remove zip code field
return $woo_checkout_fields_array;
}
新版本可以通过以下方法去掉:
// 隐藏字段
add_filter('woocommerce_shared_settings', function ($settings) {
$settings['defaultFields']['email']['required'] = false;
$settings['defaultFields']['email']['hidden'] = true;
$settings['defaultFields']['last_name']['required'] = false;
$settings['defaultFields']['last_name']['hidden'] = true;
$settings['defaultFields']['company']['required'] = false;
$settings['defaultFields']['company']['hidden'] = true;
$settings['defaultFields']['country']['required'] = false;
$settings['defaultFields']['country']['hidden'] = true;
$settings['defaultFields']['city']['required'] = false;
$settings['defaultFields']['city']['hidden'] = true;
$settings['defaultFields']['state']['required'] = false;
$settings['defaultFields']['state']['hidden'] = true;
$settings['defaultFields']['postcode']['required'] = false;
$settings['defaultFields']['postcode']['hidden'] = true;
return $settings;
});
// 如果国家或地区不填写,就需要用这个过滤器
add_filter('woocommerce_customer_get_billing_country', function ($value, $obj) {
return 'TW';
}, 10, 2);
// 如果国家或地区不填写,就需要用这个过滤器
add_filter('woocommerce_customer_get_shipping_country', function ($value, $obj) {
return 'TW';
}, 10, 2);