【问题标题】:Woocommerce Order By Billing NameWoocommerce 按帐单名称订购
【发布时间】:2017-10-24 16:13:38
【问题描述】:

我需要帮助才能通过按名字计费来订购,如果无法做到,请按 customer_id 分组。'

现在我正在使用wc_get_orders($product_id); 效果很好。它不允许任何争论。

任何帮助将不胜感激。

【问题讨论】:

  • 向我们展示数据库架构、示例数据、当前和预期输出。请阅读How-to-Ask 这里是START 了解如何提高问题质量并获得更好答案的好地方。 How to create a Minimal, Complete, and Verifiable example 尝试在rextester.com 中创建样本
  • 在此列表中是否希望按产品 ID 过滤订单,或者只想以 billing_first_name 的 ASC 顺序显示所有订单?
  • 按 billing_first_name 过滤

标签: php mysql wordpress woocommerce


【解决方案1】:
$orders= wc_get_orders( array(
'orderby' => 'billing_first_name',
'order' => 'ASC',
) );

【讨论】:

【解决方案2】:

如果有人对这里感兴趣的话是长版本...我敢肯定有一个更简单的 WP_Query 版本,我只是想不通。

SELECT order_items.order_id FROM {$wpdb->prefix}woocommerce_order_items as order_items LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->postmeta} AS postmeta ON order_items.order_id = postmeta.post_id AND postmeta.meta_key = '_billing_first_name' LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID WHERE posts.post_type = 'shop_order' AND posts.post_status IN ( '" . implode( "','", $order_status ) . "' ) AND order_items.order_item_type = 'line_item' AND order_item_meta.meta_key = '_product_id' AND order_item_meta.meta_value = '$product_id' ORDER BY postmeta.meta_value DESC

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-19
    • 1970-01-01
    • 2021-03-14
    • 1970-01-01
    • 2023-01-14
    • 2015-09-07
    相关资源
    最近更新 更多