select term_id from wp_terms where name='variable' // assume return 4 as result
select term_id from wp_terms where name='simple' // assume return 2 as result
通过上面的查询,您可以获得下面提到的更新查询中需要使用的两种产品类型的id。
UPDATE wp_term_relationships
INNER JOIN wp_terms ON (wp_term_relationships.term_taxonomy_id = wp_terms.term_id)
SET wp_term_relationships.term_taxonomy_id = '2' where wp_term_relationships.term_taxonomy_id = '4'
-- update WooCommerce variable products without variations to simple
--1
CREATE TABLE PPCD_EDI_TEMP_UPDATE
SELECT r.object_id
FROM wp_posts wp
LEFT JOIN wp_term_relationships r ON wp.ID = r.object_id
LEFT JOIN wp_postmeta SKU on SKU.post_id = wp.ID and SKU.meta_key = '_sku' -- SKU.meta_value as sku
LEFT JOIN wp_postmeta PRICE on PRICE.post_id = wp.ID and PRICE.meta_key = '_price' -- PRICE.meta_value as price
LEFT JOIN wp_wc_product_custom_lookup PCL on PCL.product_id = wp.ID
LEFT JOIN wp_term_taxonomy tt ON r.term_taxonomy_id = tt.term_taxonomy_id
LEFT JOIN wp_terms t ON t.term_id = tt.term_id
LEFT JOIN wp_posts wpv ON wp.id = wpv.post_parent AND wpv.post_type != 'attachment'
WHERE tt.taxonomy = 'product_type'
AND t.name = 'variable'
and wpv.ID is null; --test for one product, replace ; with the following: and SKU.meta_value = '10001894';
--2
UPDATE wp_term_relationships
SET term_taxonomy_id = (select term_id from wp_terms where name='simple')
WHERE term_taxonomy_id = (select term_id from wp_terms where name='variable') AND object_id IN (select object_id from PPCD_EDI_TEMP_UPDATE);
--test
SELECT SKU.meta_value as sku, PRICE.meta_value as price,
wp.id AS 'Product Id',
wpv.id AS 'Variant Id',
wp.post_title as parent_title,
wpv.post_title as variant_title,
wpv.post_excerpt
FROM wp_posts wp
LEFT JOIN wp_term_relationships r ON wp.ID = r.object_id
LEFT JOIN wp_postmeta SKU on SKU.post_id = wp.ID and SKU.meta_key = '_sku' -- SKU.meta_value as sku
LEFT JOIN wp_postmeta PRICE on PRICE.post_id = wp.ID and PRICE.meta_key = '_price' -- PRICE.meta_value as price
LEFT JOIN wp_wc_product_custom_lookup PCL on PCL.product_id = wp.ID
LEFT JOIN wp_term_taxonomy tt ON r.term_taxonomy_id = tt.term_taxonomy_id
LEFT JOIN wp_terms t ON t.term_id = tt.term_id
LEFT JOIN wp_posts wpv ON wp.id = wpv.post_parent AND wpv.post_type != 'attachment'
WHERE tt.taxonomy = 'product_type'
AND t.name = 'variable'
and wpv.ID is null;
3条答案
按热度按时间sczxawaw1#
首先从MySQL备份您的数据库,然后您可以从下面的查询中获取您的产品类型的ID:
通过上面的查询,您可以获得下面提到的更新查询中需要使用的两种产品类型的id。
hc8w905p2#
首先用循环得到所有变量的乘积。使用每个产品帖子ID,获取可用的变体。如果该产品没有任何变化。然后将每个都更改为简单。
cbjzeqam3#