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

问题描述

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

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

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

我尝试了 while famloop: 这仅设置购物车和结帐页面的国家/地区,但未通过提交发送国家/地区。

解决方法

您错过了 WC_Customer save() 方法......

您可以使用静态或动态用户 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();

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...