I’m trying to use SQL to retrieve Woocommerce order item meta keys and values so that I can summarise the information in my own report, but I am really struggling to extract meta keys and values as columns. Could anyone provide any SQL examples? Is there a Wordpress API I can use for metadata?
I have tried creating the following SQL as a basis for extending the query for product information. It returns the right kind of data but only a single row:
SELECT O.order_item_id, O.order_item_name,
MAX(IF(OIM.meta_key = 'class', OIM.meta_value, NULL)) AS class
FROM wp_woocommerce_order_items AS O
LEFT JOIN wp_woocommerce_order_itemmeta AS OIM on O.order_item_id =
OIM.order_item_id
WHERE O.order_item_name='Smiths Night School';
Thanks