![](/img/trans.png)
[英]WooCommerce: Set default Country in Billing (using Geo Location) but not in Shipping in checkout page
[英]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.