用于更改WooCommerce产品变体税的SQL查询

时间:2022-10-25 10:15:10

I have a problem with a woocommerce store. Random products have ended up with the variation tax value set as 'standard' which is overriding the products actual tax class setting of 'zero-rate'.

我有一个woocommerce商店的问题。随机产品最终将变化税值设置为“标准”,这超出了产品实际税级设置的“零税率”。

To resolve this all that needs to be done is for the _tax_class values of the product variations (not the parent products) to be set to 'parent'. Once this is done woocommerce will default the _tax_class of the product itself.

要解决此问题,需要做的就是将产品变体(而不是父产品)的_tax_class值设置为“父”。一旦完成,woocommerce将默认产品本身的_tax_class。

So far I've created the following script to enable me to manually amend the tax classes from within PHPMyAdmin, however, I'm unable to edit any values because of the error mentioned below the query.

到目前为止,我已经创建了以下脚本,使我能够从PHPMyAdmin中手动修改税级,但是,由于查询下面提到的错误,我无法编辑任何值。

SELECT wp_postmeta.* , wp_posts.post_type, wp_posts.post_title, wp_posts.ID

FROM wp_postmeta INNER JOIN wp_posts  

ON wp_posts.id = wp_postmeta.post_id

WHERE wp_postmeta.meta_key = '_tax_class' AND wp_posts.post_type = 'product_variation'  

Error message;

错误信息;

'Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available'

'当前选择不包含唯一列。网格编辑,复选框,编辑,复制和删除功能不可用'

I've believe this may be an indexing issue due to the large database size (300mb uncompressed) but ive been unable to get it to see the primary key of either tables.

我相信这可能是一个索引问题,因为数据库大小很大(300mb未压缩),但我一直无法让它看到任何一个表的主键。

Any help or pointers would be great!!

任何帮助或指针都会很棒!!

Thanks

谢谢

1 个解决方案

#1


3  

Here is a pure SQL query to update all your product variations Tax class to a 'parent' value:

这是一个纯SQL查询,用于将所有产品变体Tax类更新为“父”值:

UPDATE `wp_postmeta`
SET `meta_value` = 'parent'
WHERE `meta_key` LIKE '_tax_class'
  AND `post_id` IN
    (SELECT `ID`
     FROM `wp_posts`
     WHERE `post_type` = 'product_variation');

This is tested and works

这是经过测试和运作的

But… before running this query you should do a database backup

但是......在运行此查询之前,您应该进行数据库备份

#1


3  

Here is a pure SQL query to update all your product variations Tax class to a 'parent' value:

这是一个纯SQL查询,用于将所有产品变体Tax类更新为“父”值:

UPDATE `wp_postmeta`
SET `meta_value` = 'parent'
WHERE `meta_key` LIKE '_tax_class'
  AND `post_id` IN
    (SELECT `ID`
     FROM `wp_posts`
     WHERE `post_type` = 'product_variation');

This is tested and works

这是经过测试和运作的

But… before running this query you should do a database backup

但是......在运行此查询之前,您应该进行数据库备份