woocommerce删除所有产品

DELETE relations.*, taxes.*, terms.*
FROM wp_term_relationships AS relations
INNER JOIN wp_term_taxonomy AS taxes
ON relations.term_taxonomy_id=taxes.term_taxonomy_id
INNER JOIN wp_terms AS terms
ON taxes.term_id=terms.term_id
WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'));
 
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'));
DELETE FROM wp_posts WHERE post_type IN ('product','product_variation');
------------------------------------------------
关于目录:
wp_term_relationships表包含三个字段:字段object_id是对象ID,关联表wp_posts表;term_taxonomy_id字段是分类ID,关联wp_term_taxonomy表ID。哪个对象/产品/文章/菜单 属于哪个分类都是存储在wp_term_relationships表中。
对象ID(产品id)  分类ID  分类排序

 

 

 

 

  • wp_postmeta:存储文章(包括页面、上传文件、修订)的元数据
  • wp_posts:存储文章(包括页面、上传文件、修订)
  • wp_termmeta:存储网站分类和标签的属性
  • wp_terms:存储WordPress目录和标签
  • wp_term_relationships:存储每个文章、链接和对应分类的关系
  • wp_term_taxonomy:存储每个目录、标签所对应的分类

属性信息:

 

 

 

 

 

 

 

 

 

关于产品

 

 

 


---------------------------------------------

在wp_posts表中查到产品和他对应的变种的ID

 select ID from wp_posts where post_type = 'product' and post_parent = 0 \G; 

然后根据主品的ID查出其自己变种的I

1
select ID from wp_posts where post_type ='product_variation' and post_parent = 1165 \G;  #获取产品变种的id

select * from wp_postmeta where post_id in(1165,1171,1172,1173,1174) and meta_key like '%price%' \G;


全部shell执行代码:

复制代码
#!/bin/bash

DB_INFO='/var/html/www.test.com/wp-config.php'
WEBSITE_DB=$(cat $DB_INFO| grep DB_NAME | awk '{print $3}'  | tr -d "'")
HOST_INFO=$(cat  $DB_INFO| grep DB_HOST | awk '{print $3}'  | tr -d "'")
HOST_PWSD=$(cat  $DB_INFO| grep DB_PASSWORD | awk '{print $3}'  | tr -d "'")

echo $WEBSITE_DB


#导出主产品ID
BaseSql='use '$WEBSITE_DB';'
GetPid="select ID from wp_posts where post_type = 'product' and post_parent = 0 ;";
OPTSQL=$BaseSql$GetPid
mysql -h$HOST_INFO -uroot -p$HOST_PWSD -e "${OPTSQL}" > /data/chage_product_price/pidtxt
sed -i '1d' /data/chage_product_price/pidtxt
pidArr=$(cat /data/chage_product_price/pidtxt)

#循环处理主品
for x in ${pidArr[@]}
do
        #获取对应的变种,并且以逗号隔开
        getVar="SET SESSION group_concat_max_len=102400; select GROUP_CONCAT(ID) from wp_posts where post_type ='product_variation' and post_parent = $x;"

        getVarSql=$BaseSql$getVar
        mysql -h$HOST_INFO -uroot -p$HOST_PWSD -e "${getVarSql}" > /data/chage_product_price/$x'_txt'
        sed -i '1d' /data/chage_product_price/$x'_txt'
        varArr=$(cat /data/chage_product_price/$x'_txt')
        ids=$x','$varArr

        echo $x'开始处理'
        #更新post_meta
        metaSql="update wp_postmeta set meta_value = round(meta_value*0.88, 0) where post_id in($ids) and meta_key in('_price','_regular_price','_sale_price') and meta_value != '';"
        
        #更新meta_lookup
        metalookSql="update  wp_wc_product_meta_lookup set min_price = round(min_price*0.88, 0), max_price = round(max_price*0.88, 0) where product_id in($ids);"
        
        #删除options数据
        optionSql="delete from wp_options where option_name like '%_transient_wc_var_prices_$x%';"

        runSql=$BaseSql$metaSql$metalookSql$optionSql
        mysql -h$HOST_INFO -uroot -p$HOST_PWSD -e "${runSql}"
        echo $x'处理完成'
        rm /data/chage_product_price/$x'_txt'
done
复制代码

 

posted @ 2022-07-26 23:02  也许明天  阅读(665)  评论(0编辑  收藏  举报