【发布时间】:2018-04-13 13:02:47
【问题描述】:
如何在 woo-commerce 中按产品 ID 获取所有订单详细信息,我的代码很糟糕,但我无法获取详细信息。
function getProductId($id){
$customer_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
) );
foreach ($customer_orders as $customer) {
$order = wc_get_order( $customer->ID );
$items = $order->get_items();
foreach ( $items as $item ) {
if ($id == $item->get_product_id())
return true;
}
} } global $product; $id = $product->get_id(); getProductId($id);
【问题讨论】:
标签: php wordpress woocommerce