forked from mauran/Woocommerce-delete-all-orders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wooDelete.php
67 lines (52 loc) · 1.91 KB
/
wooDelete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <mauran@mauran.me> wrote this file.
* As long as you retain this notice you can do whatever you want with this
* stuff. If we meet some day, and you think this stuff is worth it, you can
* buy me a beer in return --Mauran Muthiah
* ----------------------------------------------------------------------------
*/
// 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! :-)';