【发布时间】:2017-03-26 21:52:10
【问题描述】:
我在前端有一个受密码保护的页面。在该页面上,我想显示与单个 woocommerce 产品 ID 关联的所有购买的完整列表。
选项 1:
我查看了woocommerce docs,发现:
WC_CLI_Order 和一个列出所有订单的list_( $args, $assoc_args ) 函数。
想必可以通过product id过滤订单
[--=] 根据订单属性过滤订单。
订单项字段(数字数组,从索引零开始):
line_items.0.product_id
选项 2:
我found this article,但它基于客户 ID。我已经根据对 meta_key 和 meta_value 的猜测修改了代码。
$customer_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_product',
'meta_value' => get_product_id(),
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
) );
如何显示单个产品的所有订单,首先显示最近的订单?
【问题讨论】:
-
您是否尝试过更改查询以根据您的产品进行购买?像 get_purchases(array('product' => 'pencil')) 它正在构建您需要的查询玩具。我不是 woocommerce 方面的专家。但我认为这些数组应该是一个查询键,如果 meta_value 不在您的表中,则不需要它
标签: php wordpress woocommerce custom-wordpress-pages