Skip to content

Instantly share code, notes, and snippets.

@JAW-Dev
Created April 8, 2020 14:03
Show Gist options
  • Save JAW-Dev/71b3438ab408bad48ed427d6673c408b to your computer and use it in GitHub Desktop.
Save JAW-Dev/71b3438ab408bad48ed427d6673c408b to your computer and use it in GitHub Desktop.
MG Report Quries
Order Today
====================================
SELECT
wo.shipping_first_name as 'First Name',
wo.shipping_last_name as 'Last Name',
wo.shipping_city as 'City',
wo.shipping_state as 'State',
wo.total as 'Total'
FROM wp_woocommerce_orders wo
INNER JOIN wp_posts p on wo.order_id = p.ID
WHERE DATE(p.post_date) = CURDATE()
AND p.post_status IN ('wc-processing', 'wc-awaiting-shipment', 'wc-completed')
Low Stock
====================================
SELECT p.ID as 'ID', p.post_title as 'Name', pm.meta_value as 'SKU', pm2.meta_value as 'Stock'
FROM wp_posts p
INNER JOIN wp_postmeta pm
ON p.ID = pm.post_id
INNER JOIN wp_postmeta pm2
ON p.ID = pm2.post_id
AND pm.meta_key = '_sku'
AND ((pm2.meta_key = '_stock' AND CAST(pm2.meta_value AS SIGNED) BETWEEN '1' AND '4' ))
Out of Stock
====================================
SELECT p.post_title as 'Name', pm.meta_value as 'SKU', pm2.meta_value as 'Stock'
FROM wp_posts p
INNER JOIN wp_postmeta pm
ON p.ID = pm.post_id
INNER JOIN wp_postmeta pm2
ON p.ID = pm2.post_id
AND pm.meta_key = '_sku'
AND ((pm2.meta_key = '_stock' AND pm2.meta_value = '0' ))
Top Markets
====================================
SELECT
any_value(shipping_state) as 'State',
any_value( shipping_city) as 'City',
shipping_postcode as 'Postal Code',
COUNT(order_id) as 'Orders',
ROUND(SUM(total), 2) as 'Subtotal'
FROM wp_woocommerce_orders
GROUP BY shipping_postcode
ORDER BY Subtotal
DESC
LIMIT 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment