问题描述
我使用 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();
现在它作为用户元数据保存在数据库中。