首页 > 解决方案 > WooCommerce 从所有订单中获取最大商品购买数量

问题描述

function get_maximum_line_item_from_all_orders($all_order_ids) {
        $max_line_items = 0;
        foreach ($all_order_ids as $order_id) {
            $order = wc_get_order($order_id);
            $line_items_count = count($order->get_items());
            if ($line_items_count >= $max_line_items) {
                $max_line_items = $line_items_count;
            }
        }
        return $max_line_items;
    }

使用上述函数,我可以从 WooCommerce 中的所有订单中获取最大订单项数。

有没有更快的方法来实现这一点(可能对{$wpdb->prefix}woocommerce_order_items表进行一些 MySQL 查询)而不循环整个订单。?

标签: phpwordpresswoocommercehook-woocommerceorders

解决方案


推荐阅读