WooCommerce 从所有订单中获取最大商品购买数量

时间:2021-05-19 04:29:57

标签: php wordpress woocommerce hook-woocommerce orders

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 查询)而不循环整个订单。?

0 个答案:

没有答案