0

I'm trying to bulk update the cost of certain items on my store. I found this thread where a user says the following code can bulk update price:

UPDATE wp_postmeta m 
    JOIN wp_posts p ON m.post_id=p.id 
    AND m.meta_key = '_price' 
    AND p.post_type = 'product'
SET m.meta_value = <price>

I'm gonna assume if I change _price to _cost it will work. Is that the correct term, or does anyone know how I can find it?

More importantly, am I able to target certain products by their categories or tags? If so, how?

Community
  • 1
  • 1
vytfla
  • 549
  • 2
  • 9
  • 29

1 Answers1

2

There is no term like _cost in woocommerce.

There are 3 terms that WooCommerce use to store data in database:

1) _regular_price : As the name suggests, It is for the regular price of the product.

2) _sale_price : As the name suggests, It is for the sale price if the product is on sale and if product is not on sale then it will use _regular_price.

3) _price : Product is going to be sell based on _price. So suppose you have on product which is having _regular_price 22 $ and _sale_price 18 $ then product is going to sell at 18 $. So basically you can say _price is decide by the regular_price and _sale_price both.

So there is not _cost term as per my knowledge and experience.


Yes you can target particular category but you need to dig in to database.

First step : Go to your database and find wp_terms table(wp is prefix and it might be different in your case).

Step 2 : Find term_id of your category.

All the category assigned to the product in wp_term_relationships.

So you can write your query and put condition like id(wp_post table) = object_id(wp_term_relationships table).

NOTE: Object ID and Post ID both are same in your database.

Rohil_PHPBeginner
  • 6,002
  • 2
  • 21
  • 32