-
Notifications
You must be signed in to change notification settings - Fork 0
/
WOOSQLtoCSV.php
39 lines (30 loc) · 2.33 KB
/
WOOSQLtoCSV.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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "wordpress";
$countorder = 0;
$conn = mysqli_connect($servername,$username,$password,$dbname);
if(!$conn){
die("connection failed: " . mysqli_connect_error());
}
$query = "SELECT i.order_id, a.address_type, a.first_name, a.last_name, a.company, a.address_1, a.address_2, a.city, a.postcode, a.state, a.phone, a.email, i.order_item_type, rp.product_id, rp.variation_id, rp.customer_id, rp.date_created, rp.product_qty, rp.product_net_revenue, rp.product_gross_revenue, rp.coupon_amount, rp.tax_amount, rp.shipping_amount, rp.shipping_tax_amount FROM wp_wc_order_addresses a LEFT JOIN wp_woocommerce_order_items i ON i.order_id = a.order_id LEFT JOIN wp_wc_order_product_lookup rp ON i.order_item_id=rp.order_item_id";
$userdata = mysqli_query($conn, $query);
$list = array();
$list[0] = array('order_id','address_type','first_name','last_name','company','address_1','address_2','city','postcode','state','phone','email','order_item_type','product_id','variation_id','customer_id','date_created','product_qty','product_net_revenue','product_gross_revenue','coupon_amount','tax_amount','shipping_amount','shipping_tax_amount');
if(mysqli_num_rows($userdata) > 0){
while($row = mysqli_fetch_assoc($userdata)){
$countorder++;
$list[$countorder + 1] = array($row["order_id"], $row["address_type"], $row["first_name"], $row["last_name"], $row["company"], $row["address_1"], $row["address_2"], $row["city"], $row["postcode"], $row["state"], $row["phone"], $row["email"], $row["order_item_type"], $row["product_id"], $row["variation_id"], $row["customer_id"], $row["date_created"], $row["product_qty"], $row["product_net_revenue"], $row["product_gross_revenue"], $row["coupon_amount"], $row["tax_amount"], $row["shipping_amount"], $row["shipping_tax_amount"]);
}
} else {
echo "0 results";
}
echo "<h2>Done!</h2><br>";
$fp = fopen('file.csv', 'w');
foreach($list as $fields){
fputcsv($fp, $fields);
}
fclose($fp);
mysqli_close($conn);
?>