我只想将国家/地区字段预先填充到非用户的 woocommerce 结帐中。所以两个过滤器分开工作但不能一起工作,我可以将它们组合在一起吗?
add_filter('woocommerce_checkout_get_value', function($input, $key) {
global $current_user;
// Return the user property if it exists, false otherwise
return ($current_user->$key
? $current_user->$key
: false
);
}, 10, 2);
使用此过滤器,我尝试将国家/地区设置为默认值,但它会被上部函数覆盖
add_filter( 'default_checkout_country', 'change_default_checkout_country' );
function change_default_checkout_country() {
return 'DE'; // country code
}
谢谢你的帮助 :)