重置所有 WooCommerce 产品库存为 0

huangapple go评论50阅读模式
英文:

Resetting all woocommerce products stock to 0

问题

我有大约5,000个产品在我的商店,我想知道是否有一种通过PhpMyAdmin或您可能知道的任何其他插件的方法,可以将所有我的可变产品的库存水平设置为0,因为我每天都会上传一个新的CSV文件。

通过PhpMyAdmin是否可以将每个产品的整个库存重置为0,并将库存状态设置为“缺货”,以便我可以导入我的新CSV文件,并仅更新现有产品。

英文:

I have around 5k products in my store and I wonder if there is a way via PhpMyAdmin or any other plugin you might know to set all my stock levels from variables products to 0 due to the fact I upload every day a new CSV.

Is it possible via PhpMyAdmin to reset the entire to 0 of every product and the stock status to 'out of stock' so I can import my new CSV and update only the products are in.

答案1

得分: 1

关于您要翻译的内容,以下是翻译好的部分:

"As your question is not very clear regarding the type of products that you want to alter. In the code below, the 2 SQL queries will (for all the products):

  • Set the stock quantity to 0 (zero)
  • Set the stock status to 'Out of stock'

Always before, be sure to make a backup of the database.

The query to set the stock quantity to 0:

UPDATE wp_postmeta pm
INNER JOIN wp_wc_product_meta_lookup pml
    ON pm.post_id =  pml.product_id
SET pm.meta_value = '0', pml.stock_quantity = '0'
WHERE pm.meta_key = '_stock';

The query to set the stock status 'Out of stock':

UPDATE wp_postmeta pm
INNER JOIN wp_wc_product_meta_lookup pml
    ON pm.post_id =  pml.product_id
SET pm.meta_value = 'outofstock', pml.stock_status = 'outofstock'
WHERE pm.meta_key = '_stock_status';

Tested, works.

Note: For the stock status, it should also require to INSERT IN wp_term_relationships table all the related product IDs with the term ID corresponding to the term slug 'outofstock'. It will make 5000 inserts, as you have 5000 related products."

英文:

As your question is not very clear regarding the type of products that you want to alter. In the code below, the 2 SQL queries will (for all the products):

  • Set the stock quantity to 0 (zero)
  • Set the stock status to "Out of stock"

Always before, be sure to make a backup of the database.

The query to set the stock quantity to 0:

UPDATE wp_postmeta pm
INNER JOIN wp_wc_product_meta_lookup pml
    ON pm.post_id =  pml.product_id
SET pm.meta_value = '0', pml.stock_quantity = '0'
WHERE pm.meta_key = '_stock';

The query to set the stock status "Out of stock":

UPDATE wp_postmeta pm
INNER JOIN wp_wc_product_meta_lookup pml
    ON pm.post_id =  pml.product_id
SET pm.meta_value = 'outofstock', pml.stock_status = 'outofstock'
WHERE pm.meta_key = '_stock_status';

Tested, works.

> Note: For the stock status, it should also require to INSERT IN wp_term_relationships table all the related product IDs with the term ID corresponding to the term slug "outofstock". It will make 5000 inserts, as you have 5000 related products.

huangapple
  • 本文由 发表于 2023年7月3日 03:55:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76600551.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定