Skip to content

Instantly share code, notes, and snippets.

@kloon
Created December 18, 2014 05:25
Show Gist options
  • Save kloon/3e9df9445f4940952f17 to your computer and use it in GitHub Desktop.
Save kloon/3e9df9445f4940952f17 to your computer and use it in GitHub Desktop.
WC 2.2 Order Status Updates
/* 1. Update Pending Orders */
UPDATE wp_posts as posts
LEFT JOIN wp_term_relationships AS rel ON posts.ID = rel.object_ID
LEFT JOIN wp_term_taxonomy AS tax USING( term_taxonomy_id )
LEFT JOIN wp_terms AS term USING( term_id )
SET posts.post_status = 'wc-pending'
WHERE posts.post_type = 'shop_order'
AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status'
AND term.slug LIKE 'pending%';
/* 2. Update Processing Orders */
UPDATE wp_posts as posts
LEFT JOIN wp_term_relationships AS rel ON posts.ID = rel.object_ID
LEFT JOIN wp_term_taxonomy AS tax USING( term_taxonomy_id )
LEFT JOIN wp_terms AS term USING( term_id )
SET posts.post_status = 'wc-processing'
WHERE posts.post_type = 'shop_order'
AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status'
AND term.slug LIKE 'processing%';
/* 3. Update On-Hold Orders */
UPDATE wp_posts as posts
LEFT JOIN wp_term_relationships AS rel ON posts.ID = rel.object_ID
LEFT JOIN wp_term_taxonomy AS tax USING( term_taxonomy_id )
LEFT JOIN wp_terms AS term USING( term_id )
SET posts.post_status = 'wc-on-hold'
WHERE posts.post_type = 'shop_order'
AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status'
AND term.slug LIKE 'on-hold%';
/* 4. Update Completed Orders */
UPDATE wp_posts as posts
LEFT JOIN wp_term_relationships AS rel ON posts.ID = rel.object_ID
LEFT JOIN wp_term_taxonomy AS tax USING( term_taxonomy_id )
LEFT JOIN wp_terms AS term USING( term_id )
SET posts.post_status = 'wc-completed'
WHERE posts.post_type = 'shop_order'
AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status'
AND term.slug LIKE 'completed%';
/* 5. Update Cancelled Orders */
UPDATE wp_posts as posts
LEFT JOIN wp_term_relationships AS rel ON posts.ID = rel.object_ID
LEFT JOIN wp_term_taxonomy AS tax USING( term_taxonomy_id )
LEFT JOIN wp_terms AS term USING( term_id )
SET posts.post_status = 'wc-cancelled'
WHERE posts.post_type = 'shop_order'
AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status'
AND term.slug LIKE 'cancelled%';
/* 6. Update Refunded Orders */
UPDATE wp_posts as posts
LEFT JOIN wp_term_relationships AS rel ON posts.ID = rel.object_ID
LEFT JOIN wp_term_taxonomy AS tax USING( term_taxonomy_id )
LEFT JOIN wp_terms AS term USING( term_id )
SET posts.post_status = 'wc-refunded'
WHERE posts.post_type = 'shop_order'
AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status'
AND term.slug LIKE 'refunded%';
/* 7. Update Failed Orders */
UPDATE wp_posts as posts
LEFT JOIN wp_term_relationships AS rel ON posts.ID = rel.object_ID
LEFT JOIN wp_term_taxonomy AS tax USING( term_taxonomy_id )
LEFT JOIN wp_terms AS term USING( term_id )
SET posts.post_status = 'wc-failed'
WHERE posts.post_type = 'shop_order'
AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status'
AND term.slug LIKE 'failed%';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment