SQL templates/WooCommerce

Repeat purchase rate in WooCommerce

Share of WooCommerce customers (by email) with more than one order.

WooCommerce · PostgreSQL
SELECT ROUND(100.0 * COUNT(*) FILTER (WHERE n > 1) / NULLIF(COUNT(*), 0), 1) AS repeat_rate_pct
FROM (
  SELECT em.meta_value AS email, COUNT(*) AS n
  FROM wp_posts p
  JOIN wp_postmeta em ON p."ID" = em.post_id AND em.meta_key = '_billing_email'
  WHERE p.post_type = 'shop_order'
    AND p.post_status IN ('wc-completed', 'wc-processing')
  GROUP BY em.meta_value
) y;

How it works

Counts orders per billing email, then the percentage with more than one — a core retention KPI you can chart over time.

Run this on your own database

BeQuery mirrors your WooCommerce MySQL database to an isolated PostgreSQL copy, so you can run queries like this one without ever touching production.

Start free No credit card