Skip to content

Instantly share code, notes, and snippets.

@mmilosheski
Last active March 19, 2018 12:02
Show Gist options
  • Save mmilosheski/d3edcdc669f9f5cee172c20b14cab9a2 to your computer and use it in GitHub Desktop.
Save mmilosheski/d3edcdc669f9f5cee172c20b14cab9a2 to your computer and use it in GitHub Desktop.
<?php
// By default wp_ for standard WP-installations
$prefix = 'wp_';
// Database infos here
$host = 'localhost';
$username = 'user';
$password = 'password';
$db = 'dbname';
$conn = new mysqli($host, $username, $password, $db);
if ($conn->connect_error) {
die('Whoops: '.$conn->connect_error);
}
$sql = 'DELETE FROM '.$prefix.'woocommerce_order_itemmeta';
if ($conn->query($sql) === true) {
echo 'Deleted woocommerce_order_itemmeta '.PHP_EOL;
} else {
echo 'Whoops: '.$conn->error;
}
$sql = 'DELETE FROM '.$prefix.'woocommerce_order_items';
if ($conn->query($sql) === true) {
echo 'Deleted woocommerce_order_items'.PHP_EOL;
} else {
echo 'Whoops: '.$conn->error;
}
$sql = 'DELETE FROM '.$prefix."comments WHERE comment_type = 'order_note'";
if ($conn->query($sql) === true) {
echo "Deleted comments where comment_type = 'order_note'".PHP_EOL;
} else {
echo 'Whoops: '.$conn->error;
}
$sql = "DELETE FROM ".$prefix."postmeta WHERE post_id IN ( SELECT ID FROM ".$prefix."posts WHERE post_type = 'shop_order' )";
if ($conn->query($sql) === true) {
echo "Deleted all rows from postmeta which belonged to posts with post_type = 'shop_order'".PHP_EOL;
} else {
echo 'Whoops: '.$conn->error;
}
$sql = 'DELETE FROM '.$prefix."posts WHERE post_type = 'shop_order'";
if ($conn->query($sql) === true) {
echo "Deleted posts where post_type = 'shop_order'".PHP_EOL;
} else {
echo 'Whoops: '.$conn->error;
}
echo 'Fixed! Your woocommerce orders should be empty! :-)';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment