在我的WooCommerce结帐页面上,除了结算国家/地区外,我希望结算字段为空白。
我正在使用它来确保填写表格时结帐表格是空白的:
add_filter('woocommerce_checkout_get_value','__return_empty_string',10);
但是,我确实希望填写结算国家/地区字段,并默认为美国。所以我有这个:
add_filter( 'default_checkout_billing_country', 'change_default_checkout_country' );
function change_default_checkout_country() {
return 'US';
}
但只要我有第一个过滤器,该字段就显示为空白。除结算国家/地区外,如何将所有字段留空?
Try the following instead, that will blank all checkout field, except the billing and shipping countries that will be set to a specific country:
add_filter('woocommerce_checkout_get_value', 'checkout_get_value_filter', 10, 2 );
function checkout_get_value_filter( $value, $input ) {
// The defined country code
$country_code = 'US';
// Set the billing and shipping country
WC()->customer->set_billing_country($country_code);
WC()->customer->set_shipping_country($country_code);
// Display only the billing and shipping country
if( 'billing_country' === $input || 'shipping_country' === $input ){
return $country_code;
} else {
return '';
}
}
代码在您的活动子主题(或活动主题)的function.php文件中。经过测试和工作。