Search code examples
sqlwordpresscsvwoocommerce

How to import woocommerce products from csv or xls to woocommerce with sql


I'm trying to import a 700000 product list to woocommerce and it's taking forever.

Is there a way to import it directly from the csv file to the SQL database? the csv file have 5 columns:

Part Number=SKU 
Part Name=post_title 
Manufacturer=taxonomy:manufacturer 
Sale Price=sale_price 
Regular Price=regular_price

I have found an answer here but it doesn't explain how to get the data from the csv file.

product import via csv to woocommerce with sql

to import woocommerce products it will need to be done in both wp_posts and in wp_postmeta which is why i'm asking for help, since i'm inserting into existing tables.

Thanks in advance


Solution

  • You can directly insert csv data into SQL by using BULK INSERT command, Syntax as follows,

    BULK INSERT INTO TABLE
    FROM '(a)'
    WITH
    (
    ROWTERMINATOR = '(b)',
    FIELDTERMINATOR = '(c)'
    )
    

    where,

    1. a = Location of CSV file on the SQL Server, file location cannot be on any local machine
    2. b = Escape character for line break e.g write \n in case rows are separated by new row
    3. c = escape character for next column value

    Please note that schema of csv file should be equal to table imported into.