繁体   English   中英

以编程方式设置 WooCommerce 用户计费和发货国家/地区

[英]Set WooCommerce user billing and shipping country programmatically

我使用 WooCommerce 并构建了一些自定义函数。 我想要的最后一件事是以编程方式设置计费和发货的国家/地区。

我从结帐页面中删除了输入 billing_country 和 shipping_country。

有没有办法以编程方式设置 billing_country 和 shipping_country?

我试过WC()->customer->set_shipping_country('US'); 这仅设置购物车和结帐页面的国家/地区,但不会通过提交发送国家/地区。

你错过了WC_Customer save()方法……

您可以使用 static 中的以下内容或动态用户 ID (用户 ID 是必需的)

$country_code = 'US';

// Get the WC_Customer instance object from user ID
$customer = new WC_Customer( $user_id );

$customer->set_billing_country( $country_code );
$customer->set_shipping_country( $country_code );
$customer->save();

现在它作为用户元数据保存在数据库中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM