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"

5
  • How large is the product catalog? This might be easier to do in PHP Jan 28, 2020 at 19:42
  • @czerspalace Around 2000 products. Jan 28, 2020 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 Jan 28, 2020 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? Jan 29, 2020 at 4:17
  • this answer might help wordpress.stackexchange.com/questions/172041/… Jan 29, 2020 at 21:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.