I have this function and I only want to set the billing country if user is a guest, otherwise we should not change the billing country, but instead take the billing country as what the user has in his profile in WooCommerce.
add_filter( 'default_checkout_billing_country', 'bbloomer_change_default_checkout_country' );
function bbloomer_change_default_checkout_country() {
return 'US';
}
You could use
is_user_logged_in
:However, sometimes, because of caching issues,
is_user_logged_in
doesn't work. In that case then you could useglobal $current_user
.Let me know if you could get it to work!