Skip to content

Staging WooCommerce without syncing order tables

Web Hosting by moebig 13 replies 1.6K views
#1

Wesh everyone ! Incha'allah your shops stay up this summer. I made a small plugin for staging WooCommerce without breaking le production orders — basically it skips wp_posts (and wp_postmeta) during sync, but keeps everything else. Le server حلو when you don't overwrite 50k orders by accident, you know ?

The trick is selective table exclusion. By default WP migration plugins grab everything ; mine hooks into pre_export and filters by post_type. Orders, refunds, coupons stay on live. Products, pages, themes come to staging.

Code is rough, GPL, on my git. Incha'allah someone finds it useful !

RAID 1: because paranoia pays
#2

Very nice. But I buy yesterday a plugin that break my shop. You skip wp_wc_orders too?

#3
moebig said:
Skips wp_posts

Back when WooCommerce still stored everything in posts, that would've been enough. Kids these days forget there are dedicated tables now. You need to skip wp_wc_orders, wp_wc_order_addresses, wp_wc_order_operational_data, and the lookup tables too. Twenty years in this business, I've seen three "minimal" staging plugins corrupt HPOS stores because they didn't account for the metadata split.

Mark my words, if WooCommerce ever finishes the migration, half the staging tools on the market will break overnight.

IPv4, IRC, and irssi — fight me
3 #4
haroldgsm said:
Corrupt HPOS stores

HPOS is the future apparently legacy tables still exist though you need both paths my plugin checks wp_wc_orders first then falls back to wp_posts smart right??

#5

HPOS stores still corrupt with "minimal" plugins? Which lookup tables exactly

#6

You skip wp_wc_order_operational_data too or just the main tables

#7
alpha1997 said:
You skip wp_wc_orders too?

Wa akhi I updated the git yesterday ! Now it checks for HPOS tables and skips wp_wc_orders, wp_wc_order_addresses, wp_wc_order_operational_data. The lookup tables I leave alone because they rebuild themselves, no ?

haroldgsm said:
Corrupt HPOS stores

You are right, I saw this on a client shop in Rabat. My old version was pre-HPOS, I admit. The new hook filters by table prefix + wc_order, so anything WooCommerce adds later should catch insha'allah.

Git has tags now, v1.0 is legacy, v2.0 is HPOS-aware.

RAID 1: because paranoia pays
#8
moebig said:
The lookup tables I leave alone because they rebuild themselves

They do NOT rebuild themselves if you half-sync them. Wp_wc_order_stats gets foreign key constraints with the operational data table. You pull products and orders in the wrong sequence, you get orphaned rows and WooCommerce starts throwing "Invalid order" on the frontend.

I've had to repair three sites this year where a "smart" staging plugin left lookup tables in a split-brain state. The fix is always the same: truncate and let wc_admin_daily run, which means your client calls you at 9 AM because overnight reports are blank.

Skip them. All of them. Wp_wc_order_stats, wp_wc_order_product_lookup, wp_wc_order_tax_lookup, wp_wc_order_coupon_lookup. They regenerate from the order tables you aren't touching anyway.

IPv4, IRC, and irssi — fight me
9 #9
haroldgsm said:
Wp_wc_order_stats gets foreign key constraints

This explains why my staging site shows zero sales for August after every sync. I thought it was just caching. Using WP Migrate DB Pro with table selection, but I was including the lookup tables because "why not, they're small."

Which tables exactly do you include then? Just wp_posts for pages, wp_postmeta where meta_key not like %order%, and the product tables?

7 #10
birdbilb said:
Which tables exactly do you include

I made a list for my own plugin, maybe useful:

  • Include: wp_posts (post_type = product|page|attachment), wp_postmeta (join on post_id), wp_terms, wp_term_taxonomy, wp_term_relationships, wp_options (careful with URLs here), wp_users, wp_usermeta
  • Skip: anything wp_wc_order%, wp_wc_order_stats%, wp_wc_order_product_lookup%, wp_wc_order_tax_lookup%, wp_wc_order_coupon_lookup%
  • Maybe: wp_comments if you use product reviews, but filter comment_type

The URL in wp_options is the gotcha. I do search-replace after import, not during export, because serialized PHP breaks if you change string lengths mid-stream.

Post a reply

You need an account to reply. Log in or register to join the conversation.

Post reply Preview Save draft