【问题标题】:Set WooCommerce user billing and shipping country programmatically以编程方式设置 WooCommerce 用户计费和发货国家/地区
【发布时间】:2021-06-02 14:12:04
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: php wordpress woocommerce crud usermetadata


    【解决方案1】:

    你错过了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();
    

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

    【讨论】:

      猜你喜欢
      • 2014-03-29
      • 2021-01-14
      • 2019-02-20
      • 1970-01-01
      • 1970-01-01
      • 2018-07-23
      • 2022-11-14
      • 2018-09-25
      • 2012-07-09
      相关资源
      最近更新 更多