从 woocommerce 中的 excel 文件导入订单

Import orders from excel file in woocommerce

Create woocommerce order by Uploading Excel file

我们有一些客户的订单是直接打电话给我们订购的。所以我们将他们的详细信息保存在 excel 文件中,其中包含每个详细信息(客户姓名地址等到产品名称、产品 ID、变体 ID、折扣、优惠券详细信息等)。

我们知道如何通过 php 代码通过 excel 将数据上传到数据库。

示例

<form name="import" method="post" enctype="multipart/form-data">
    <input type="file" name="file" /><br />
    <input type="submit" name="submit" value="Submit" />
 </form>

if(isset($_POST["submit"]))
{
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file, "r");
$c = 0;

while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
{
    $name = $filesop[0];
    $email = $filesop[1];

    $sql = mysql_query("INSERT INTO order (name, email) VALUES ('$name','$email')");
}

    if($sql){
        echo "Correctly uploaded";
    }else{
        echo "it's not working";
    }

}

而且我们知道如何获取产品的每一个细节。

但请帮助与 woocommerce 集成。由于我们注意到每个订单都保存在 wp_posts 中,其中 post_type='shop_order' 和订单状态作为名为 shop_order_status 的分类法,订单的客户详细信息保存为 post_meta 字段 ets 和我们知道如何在 woocommerce 中使用每个 class 来检索数据,例如 WC_OrderWC_Order_Item_Meta.

请帮忙完成这个。如果有人能解释一下 woocommerce 的基本 table 结构,用于通过 sql 插入查询,那也是有帮助的。

谢谢。

Note : We need to create sql query . We don't need to create customer and customer meta table entries , because in this order the customer who place this order is our default company customer service account . So no need to think about customer and customer meta table . The real customer information is added into order meta fields like _billing_phone,_billing_email, _shipping_address_1 etc

我不确定,但通过在插件中进行一些自定义,这可能对您有所帮助。

https://wordpress.org/plugins/woocommerce-csvimport/

订单是自定义的 post,位于 wp_posts table 中的第一个 'post_type',例如 'shop_order'

对于每个 post_id(在 wp_posts table ID 中),您可以在 wp_postmeta table.
中检索所有订单详细信息 此订单还与 wp_woocommerce_order_itemswp_woocommerce_order_itemmeta 有关系,它们存储与购买的产品、数量、金额、增值税相关的其他详细信息...

此命令还与 wp_users(如 'customer')和 wp_usermeta table 相关。您可以在 wp_postmeta table 中检索客户 ID,其中 meta_key_customer_user

进行 sql 查询会很复杂,因为您首先需要创建用户(wp_users 和 wp_usermeta tables)。
然后一个复杂的查询同时填充 4 tables 相关的订单。

--(update)-- RETRIEVING ORDERS DATA

Table wp_posts:

SELECT * FROM 'wp_posts' WHERE 'post_type' LIKE 'shop_order'

Table wp_postmeta:

SELECT * FROM 'wp_postmeta' WHERE 'post_id' = xxxx

(xxxx is the id of an order that you can find in wp_posts table)

Table wp_woocommerce_order_items:

SELECT * FROM 'wp_woocommerce_order_items' WHERE 'order_id' = xxxx

(xxxx is the id of an order that you can find in wp_posts table)

Table wp_woocommerce_order_itemmeta:

SELECT * FROM 'wp_woocommerce_order_itemmeta' WHERE 'order_item_id' = yyyy

(yyyy is the order_item_id of an order_id that you can find in wp_woocommerce_order_items)