php - 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 查询)而不循环整个订单。?
解决方案
推荐阅读
- arrays - 根据多个数组值过滤文件行
- javascript - 即使它不在 console.log (...) 中,值为 null
- java - JdbcTemplate 插入 XmlType 在较大尺寸上失败
- react-native - 检查是否在原生 Android 模块中启用了开发者模式
- typescript - '(_: string, key: any, value: any) => void' 类型的参数不能分配给 '(substring: string, ...args: any[]) => string' 类型的参数
- sql - 根据两个表中其他列中的匹配组合两列
- angular - @types/fingerprintjs2 坏了吗?(与角度 5 一起使用)
- python - 类型错误:button_click() 缺少 1 个必需的位置参数:'self'
- android - “包安装程序已停止” - 我的应用程序在模拟器和 USB 调试上运行良好,但构建的 apk 无法安装在真手机上
- java - TransactionalStateSupport 不保存变量