【问题标题】:WooCommerce Shop Managers view orders on their specific Country costumer orders onlyWooCommerce 商店经理仅查看其特定国家客户订单的订单
【发布时间】:2021-03-23 09:46:55
【问题描述】:

我正在使用基于国家/地区限制的 WooCommerce 插件,用户只能按自己的国家/地区订购。我在 3 个国家/地区拥有 3 家实体店分店,现在我为每个国家/地区创建了 3 个 Shop Manager 角色 1,我希望他们在订单页面上进行限制,只有他们可以按指定的国家/地区查看客户订单。

我从这里找到了一个类似的问题,但仍然没有答案 Show woocommerce orders by country

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    如果您想按国家/地区查询订单。这是一个示例代码。

    // If you want to get orders from America.
    $args = array(
        'billing_country' => 'US',
    );
    $orders = wc_get_orders( $args );
    

    请参阅此文档。

    https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query#address-and-name

    对于这个问题,

    我在 3 个国家有 3 个实体店分店,现在我创建了 3 个 商店经理角色每个国家/地区 1 个,我希望他们限制 订单页面只有他们可以通过他们的特定查看客户订单 指定国家。

    我建议创建一个自定义shortcode将查询订单记录(使用上面提供的代码)使用分配给当前登录Shop Manager的当前国家/地区(我建议添加一个用户商店经理用户的元数据,您可以在其中分配国家/地区代码 - 例如 PH 、 US )和列表

    这是一个 sn-p 代码。

    $currentUserId = get_current_user_id();
    $currentShopManagerCountryCode = get_user_meta($currentUserId ,"assigned_country_code",true);
    $args = array(
        'billing_country' => $currentShopManagerCountryCode,
    );
    $orders = wc_get_orders( $args );
    

    【讨论】:

      【解决方案2】:

      我对此做了一个实验,但我不知道我在做什么,我知道这是错误的元数据等。希望你能帮助我做到这一点。

      function view_order($order, $data, $view) {
      
              $country = $order->shipping_country;
              $shop_manager_id = '';
      
              $general_santos = ['GES'];
              $koronadal = ['KOR'];
              $polomolok = ['POL'];
      
              if (in_array($country, $general_santos)) {
                  // Manually assigning the _store_manager_id using the user id, yours will differ
                  $shop_manager_id = 5;
              } else if (in_array($country, $koronadal)) {
                  $shop_manager_id = 3;
              } else if (in_array($country, $polomolok)) {
                  $shop_manager_id = 2;
              } else {
                  $shop_manager_id = 5;
              }
      
              $order->update_meta_data('_store_manager_id', $shop_manager_id);
          }
          add_action('woocommerce_view_order', 'view_order', 20, 2);
      

      【讨论】:

        猜你喜欢
        • 2021-11-20
        • 2021-11-21
        • 2018-02-03
        • 1970-01-01
        • 1970-01-01
        • 2021-06-05
        • 1970-01-01
        • 2020-10-15
        • 2021-11-21
        相关资源
        最近更新 更多