• <legend id='Qqftm'><style id='Qqftm'><dir id='Qqftm'><q id='Qqftm'></q></dir></style></legend>
  • <tfoot id='Qqftm'></tfoot>

          <bdo id='Qqftm'></bdo><ul id='Qqftm'></ul>
      1. <small id='Qqftm'></small><noframes id='Qqftm'>

        <i id='Qqftm'><tr id='Qqftm'><dt id='Qqftm'><q id='Qqftm'><span id='Qqftm'><b id='Qqftm'><form id='Qqftm'><ins id='Qqftm'></ins><ul id='Qqftm'></ul><sub id='Qqftm'></sub></form><legend id='Qqftm'></legend><bdo id='Qqftm'><pre id='Qqftm'><center id='Qqftm'></center></pre></bdo></b><th id='Qqftm'></th></span></q></dt></tr></i><div id='Qqftm'><tfoot id='Qqftm'></tfoot><dl id='Qqftm'><fieldset id='Qqftm'></fieldset></dl></div>

      2. WooCommerce 按产品元查询订单项

        时间:2023-06-06
          <tbody id='QA08P'></tbody>
        <i id='QA08P'><tr id='QA08P'><dt id='QA08P'><q id='QA08P'><span id='QA08P'><b id='QA08P'><form id='QA08P'><ins id='QA08P'></ins><ul id='QA08P'></ul><sub id='QA08P'></sub></form><legend id='QA08P'></legend><bdo id='QA08P'><pre id='QA08P'><center id='QA08P'></center></pre></bdo></b><th id='QA08P'></th></span></q></dt></tr></i><div id='QA08P'><tfoot id='QA08P'></tfoot><dl id='QA08P'><fieldset id='QA08P'></fieldset></dl></div>
        <tfoot id='QA08P'></tfoot>
        <legend id='QA08P'><style id='QA08P'><dir id='QA08P'><q id='QA08P'></q></dir></style></legend>
      3. <small id='QA08P'></small><noframes id='QA08P'>

            <bdo id='QA08P'></bdo><ul id='QA08P'></ul>
                  本文介绍了WooCommerce 按产品元查询订单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  这有点奇怪,但我很难找到如何做到这一点的答案:

                  This is a bit of an odd one, but I'm having trouble finding an answer for how to do this:

                  我正在尝试创建一个自定义查询,以获取 WooCommerce 订单中包含的所有产品(及其元数据).

                  I'm attempting to create a custom query that gets all the products (and their meta) which are contained within a WooCommerce order.

                  例如,假设我有这些订单待处理:

                  For example, let's say I have these orders pending:

                  • 产品 1
                  • 产品 2
                  • 产品 3
                  • 产品 4
                  • 产品 5
                  • 产品 6

                  我的目标是根据这些订购的产品创建一个列表,该列表按产品的元进行排序.像这样:

                  My goal is to create a list based off these ordered products, which is ordered by the product's meta. Something like this:

                  • 产品 1
                  • 产品 3
                  • 产品 4

                  但同样,这些只能是订单中的产品(包括数量).

                  But again, these would only be products (including their quantities) that sit within an order.

                  我面临的问题是订购商品"和订单项元"存储在数据库中的数据非常有限,并且不会显示与产品相关的所有信息.因此,换句话说,我没有找到一种方法来获取创建循环以创建我的列表所需的信息.

                  The problem I'm facing is that "Order Items" and "Order Item Meta" as stored in the database are quite limiting and do not display all the information associated with a product. So in other words, I'm not finding a way to get to the info I need to create the loop to create my list.

                  我的数据库技能有限,因此不胜感激!

                  My DB skills are limited so ideas would be appreciated!

                  推荐答案

                  以下是一些可能对您有所帮助的相关代码:

                  Here is some related code that might help you:

                  add_filter( 'woocommerce_shop_order_search_fields', 'woocommerce_shop_order_search_product_cat' );
                  
                  function woocommerce_shop_order_search_product_cat( $search_fields ) {
                  
                  $args = array(
                      'post_type' => 'shop_order'
                      );
                  
                  $orders = new WP_Query($args);
                  
                  if($orders->have_posts()) {
                          while($orders->have_posts()) {
                          $post = $orders->the_post();
                          $order_id = get_the_ID();
                          $order = new WC_Order($order_id);
                          $items = $order->get_items();
                          foreach($items as $item) {
                              $product_cats = wp_get_post_terms( $item['product_id'], 'product_cat' );
                              foreach($product_cats as $product_cat) {
                                  add_post_meta($order_id, "_product_cat", $product_cat->name);
                              }
                          }
                      }
                  };
                  
                  $search_fields[] = '_product_cat';
                  
                  return $search_fields;
                  
                  }
                  

                  这篇关于WooCommerce 按产品元查询订单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:更新后恢复 MySQL/var/lib/mysql 下一篇:如何替换SQL中的部分字符串

                  相关文章

                  最新文章

                • <legend id='lfYNo'><style id='lfYNo'><dir id='lfYNo'><q id='lfYNo'></q></dir></style></legend>
                  • <bdo id='lfYNo'></bdo><ul id='lfYNo'></ul>

                  <i id='lfYNo'><tr id='lfYNo'><dt id='lfYNo'><q id='lfYNo'><span id='lfYNo'><b id='lfYNo'><form id='lfYNo'><ins id='lfYNo'></ins><ul id='lfYNo'></ul><sub id='lfYNo'></sub></form><legend id='lfYNo'></legend><bdo id='lfYNo'><pre id='lfYNo'><center id='lfYNo'></center></pre></bdo></b><th id='lfYNo'></th></span></q></dt></tr></i><div id='lfYNo'><tfoot id='lfYNo'></tfoot><dl id='lfYNo'><fieldset id='lfYNo'></fieldset></dl></div>

                  <small id='lfYNo'></small><noframes id='lfYNo'>

                    1. <tfoot id='lfYNo'></tfoot>