Automattic\WooCommerce\Admin\API\Reports\Orders
DataStore::get_products_by_order_ids
Get product IDs, names, and quantity from order IDs.
Метод класса: DataStore{}
Хуков нет.
Возвращает
array.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_products_by_order_ids( $order_ids );
- $order_ids(массив) (обязательный)
- Array of order IDs.
Код DataStore::get_products_by_order_ids() DataStore::get products by order ids WC 11.1.0
protected function get_products_by_order_ids( $order_ids ) {
global $wpdb;
$order_product_lookup_table = $wpdb->prefix . 'wc_order_product_lookup';
$included_order_ids = implode( ',', $order_ids );
/* phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared */
$products = $wpdb->get_results(
"SELECT
order_id,
product_id,
variation_id,
post_title as product_name,
product_qty as product_quantity
FROM {$wpdb->posts}
JOIN
{$order_product_lookup_table}
ON {$wpdb->posts}.ID = (
CASE WHEN variation_id > 0
THEN variation_id
ELSE product_id
END
)
WHERE order_id IN ({$included_order_ids})
AND product_qty > 0
",
ARRAY_A
);
/* phpcs:enable */
return $products;
}