WC_API_Products::get_product_orders() public WC 2.4.0
Get the orders for a product
{} Это метод класса: WC_API_Products{}
Хуки из метода
Возвращает
Массив/WP_Error.
Использование
$WC_API_Products = new WC_API_Products(); $WC_API_Products->get_product_orders( $id, $fields, $filter, $status, $page );
- $id(число) (обязательный)
- the product ID to get orders for
- $fields **
- -
По умолчанию: null - $filter(массив)
- filters to include in response
- $status(строка)
- the order status to retrieve
- $page($page)
- page to retrieve
Список изменений
С версии 2.4.0 | Введена. |
Код WC_API_Products::get_product_orders() WC API Products::get product orders WC 5.0.0
public function get_product_orders( $id, $fields = null, $filter = array(), $status = null, $page = 1 ) {
global $wpdb;
$id = $this->validate_request( $id, 'product', 'read' );
if ( is_wp_error( $id ) ) {
return $id;
}
$order_ids = $wpdb->get_col( $wpdb->prepare( "
SELECT order_id
FROM {$wpdb->prefix}woocommerce_order_items
WHERE order_item_id IN ( SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE meta_key = '_product_id' AND meta_value = %d )
AND order_item_type = 'line_item'
", $id ) );
if ( empty( $order_ids ) ) {
return array( 'orders' => array() );
}
$filter = array_merge( $filter, array(
'in' => implode( ',', $order_ids ),
) );
$orders = WC()->api->WC_API_Orders->get_orders( $fields, $filter, $status, $page );
return array( 'orders' => apply_filters( 'woocommerce_api_product_orders_response', $orders['orders'], $id, $filter, $fields, $this->server ) );
}