WooCommerce:在结帐页面中默认设置国家/地区 [英] WooCommerce: Set country by default in checkout page

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

问题描述

我在我的 Wordpress 网站中使用 WooCommerce.默认情况下,结帐页面上会填充客户的帐单和运输详细信息.我希望默认情况下不会设置国家/地区.相反,即使用户已登录,它也会要求选择国家/地区.

I am using WooCommerce in my Wordpress web site. The customers billing and shipping details are populated by default on checkout page. I want that the country will not be set by default. Instead it will asked to select country even if user is logged in.

有什么建议吗?我应该怎么做才能实现这一目标?

Any suggestions? What I should do in order to achieve this?

推荐答案

更新 (自 WooCommerce 3 起)

这是用于国家/地区(和可选的州)的 woocommerce 挂钩和代码:

This are the woocommerce hooks and code to be used for this purpose for country (and optionally state):

add_filter( 'default_checkout_billing_country', 'change_default_checkout_country_and_state' );
add_filter( 'default_checkout_shipping_country', 'change_default_checkout_country_and_state' );
add_filter( 'default_checkout_billing_state', 'change_default_checkout_country_and_state' );
add_filter( 'default_checkout_shipping_state', 'change_default_checkout_country_and_state' );
function change_default_checkout_country_and_state( $default ) {
    return null;
}

或者更短:

add_filter( 'default_checkout_billing_country', '__return_null' );
add_filter( 'default_checkout_shipping_country', '__return_null' );
add_filter( 'default_checkout_billing_state', '__return_null' );
add_filter( 'default_checkout_shipping_state', '__return_null' );

代码位于活动子主题(或活动主题)的functions.php 文件中.经测试有效.

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

注意: default_checkout_countrydefault_checkout_state 钩子自 WooCommerce 3 起已被弃用和替换

Note: default_checkout_country and default_checkout_state hooks are deprecated and replaced since WooCommerce 3

相关:WooCommerce:设置国家/地区未登录用户的默认结帐页面

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

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