1

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

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

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

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

4

1 回答 1

3

你错过了WC_Customer save()方法……</p>

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

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

于 2021-03-04T00:15:48.307 回答