Posted on Leave a comment

删除所有Woocommerce产品

如果您想从WP安装中删除所有Woocommerce产品,这是一个非常有用的脚本。在根文件夹中创建一个文件,例如delete-woocommerce-products.php。将以下代码粘贴到脚本中。


require_once( 'wp-load.php' );

global $wpdb;

$sql_1 = "DELETE FROM ".$wpdb->prefix."term_relationships WHERE object_id IN (SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type = 'product');";
$sql_2 = "DELETE FROM ".$wpdb->prefix."postmeta WHERE post_id IN (SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type = 'product');";
$sql_3 = "DELETE FROM ".$wpdb->prefix."posts WHERE post_type = 'product';";

$sql_4 = "DELETE relations.*, taxes.*, terms.*
  FROM ".$wpdb->prefix."term_relationships AS relations
  INNER JOIN ".$wpdb->prefix."term_taxonomy AS taxes
    ON relations.term_taxonomy_id=taxes.term_taxonomy_id
  INNER JOIN ".$wpdb->prefix."terms AS terms
    ON taxes.term_id=terms.term_id
  WHERE object_id IN (SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type='product');";

try{
	
	$wpdb->query($sql_1);
	$wpdb->query($sql_2);
	$wpdb->query($sql_3);
	$wpdb->query($sql_4);
	
}catch(Exception $e){}

而已!现在通过调用http://yourwebsite.com/delete-woocommerce-products.php来运行脚本

发表评论

电子邮件地址不会被公开。 必填项已用*标注