Skip to content

Instantly share code, notes, and snippets.

View alexx855's full-sized avatar
πŸ”΅
Stay safe and stay optimistic

Alex Pedersen alexx855

πŸ”΅
Stay safe and stay optimistic
View GitHub Profile
@alexx855
alexx855 / mysql_query.sql
Last active October 19, 2022 14:19
WooCommerce, select users with completed orders by user role
-- ALL SUBSCRIBERS WITH AN ORDER COMPLETED
SELECT
u.ID, um.meta_value AS user_role, COALESCE(COUNT(p.ID), 0) AS completed_orders
FROM wp_users AS u JOIN wp_usermeta AS um ON u.ID = um.user_id
LEFT JOIN wp_postmeta AS pm ON pm.meta_value = um.user_id
LEFT JOIN wp_posts AS p ON p.ID = pm.post_id
WHERE um.meta_key = 'wp_capabilities'
AND um.meta_value LIKE '%subscriber%'
AND um.meta_value NOT LIKE '%administrator%'
AND pm.meta_key = '_customer_user'

Code Principles

TypeScript

  • Strict type inference only. No as assertions, no any, no ! non-null assertions
  • No type annotations when inference works. Let TS infer return types, variable types
  • Use satisfies over as when type validation needed
  • ES modules only. No require(), no dynamic import(), no conditional imports
  • Static imports at file top.