0

I'm attempting to update a large product catalogue using a SQL query via phpMyAdmin if:

  1. the _stock_status = onbackorder
  2. the _stock > 0

Queries attempted:

Update wp_postmeta 
Set meta_value = 'instock' 
Where meta_key = '_stock' 
And meta_value > 0

Update wp_postmeta 
Set meta_value = 'instock' 
Where meta_value = 'onbackorder' 
And meta_key = '_stock_status'
And meta_value > 0
And meta_key = "_stock"

Update wp_postmeta 
Set meta_value = 'instock' 
Where meta_value = 'onbackorder' 
And '_stock' > 0

None of the above have worked.
The last query reduces all stock quantities to 0 but the stock status remains on "backorder"

  • How large is the product catalog? This might be easier to do in PHP – czerspalace Jan 28 at 19:42
  • @czerspalace Around 2000 products. – UncaughtTypeError Jan 28 at 20:27
  • the data you are comparing are in different rows, so you will have to do a join to get the correct data, or in WP you can get the products $products = wc_get_products( array( 'stock_status' => 'backorder' ) ); and in the loop update as needed – czerspalace Jan 28 at 21:36
  • @czerspalace complete sql novice here, any chance you could show me what that sql query (with the join) would look like and I'll iterate and test? – UncaughtTypeError Jan 29 at 4:17
  • this answer might help wordpress.stackexchange.com/questions/172041/… – czerspalace Jan 29 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.