WooCommerce:默认情况下在结帐页面中为未登录的用户设置国家/地区 [英] WooCommerce: Set country by default in checkout page for unlogged users

查看:84
本文介绍了WooCommerce:默认情况下在结帐页面中为未登录的用户设置国家/地区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将常规(未注册用户)的国家/地区设置为默认国家/地区.但是,如果买方拥有个人帐户并进入那里的国家/地区,他会不会因为结帐而陷入默认状态?

How to make the country default for regular (unregistered users). But if the buyer has a personal account and entered the country there, he would not be thrown into default in checkout?

我尝试使用 WooCommerce:设置国家/地区默认情况下,在结帐页面上显示答案,但是它确实适用于所有已登录用户和访客…

I have tried to use WooCommerce: Set country by default in checkout page answer, but it does work for all users logged in and guest…

如何仅为未注册用户设置默认国家/地区?

How to set the default country only for unregistered users?

推荐答案

按如下所示使用 is_user_logged_in()条件标记:

Use is_user_logged_in() conditional tag as follows:

add_filter( 'default_checkout_billing_country', 'change_default_checkout_country' );
add_filter( 'default_checkout_shipping_country', 'change_default_checkout_country' );
function change_default_checkout_country( $default ) {
    if ( ! is_user_logged_in() ) {
        $default = null;
    }
    return $default;
}

代码进入活动子主题(或活动主题)的functions.php文件中.经过测试,可以正常工作.

Code goes in functions.php file of the active child theme (or active theme). Tested and works.

相关: WooCommerce:默认情况下,将国家/地区设置为结帐页面

这篇关于WooCommerce:默认情况下在结帐页面中为未登录的用户设置国家/地区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆