WooCommerce从3.1版本开始支持产品的CSV文件导入与导出,仅仅只需要用一份CSV文件的导入与导出操作就可以实现WooCommerce商店中所有产品的创建、更新操作。还需说明的是,这种通过CSV文件的导入与导出操作支持所有产品类型,当然包含产品变量。
这也就表明,再也不需要一个一个点点点的上传产品,相反我们只需要收集好产品信息,在CSV文件中统一整理好后上传WooCommerce,产品就上传完成了。
这么做至少有两个好处,其一是节省时间,规范SOP流程,再也不用为了上传产品抓狂;其二是规范后台产品信息,利于后续主机性能优化与产品SEO优化。
一、模板文件
1. 官网下载
你可以直接在WooCommerce官网下载产品信息模板文件,该文件是标准的WooCommerce产品信息文件,里面包含所有的商品通用信息字段(见下表)。
Column | Product Property | Example | Notes |
ID | id | 100 | Defining this will overwrite data for that ID on import. |
Type | type | simple, variation, virtual | Product Type. Valid values: simple, variable, grouped, external, variation, virtual, downloadable. Multiple types can be used CSV separated. |
SKU | sku | my-sku | Required. Auto-generated if missing. |
Name | name | My Product Name | Required. |
Published | status | 1 | 1 for published, 0 for private, -1 for draft. |
Is featured? | featured | 1 | 1 or 0 |
Visibility in catalog | catalog_visibility | visible | Supported values: visible, catalog, search, hidden |
Short description | short_description | This is a product. | |
Description | description | This is more information about a product. | |
Date sale price starts | date_on_sale_from | 2013-06-07 10:53:15 | Date or leave blank. |
Date sale price ends | date_on_sale_to | 2013-06-07 10:53:15 | Date or leave blank. |
Tax status | tax_status | taxable | Supported values: taxable, shipping, none |
Tax class | tax_class | standard | Can use any existing tax class. |
In stock? | stock_status | 1 | 1 or 0 |
Stock | manage_stock / stock_quantity | 20 | Numeric stock level enables stock management. parent can be used for variations. Blank = no stock management. |
Low stock amount | low_stock_amount | 3 | Empty or a number |
Backorders allowed? | backorders | 1 | 1, 0, or notify |
Sold individually? | sold_individually | 1 | 1 or 0 |
Weight (unit) | weight | 100 | Parse only numbers. |
Length (unit) | length | 20 | Parse only numbers. |
Width (unit) | width | 20 | Parse only numbers. |
Height (unit) | height | 20 | Parse only numbers. |
Allow customer reviews? | reviews_allowed | 1 | 1 or 0 |
Purchase Note | purchase_note | Thanks for buying it buddy. | |
Sale price | sale_price | 20.99 | Sale price. |
Regular price | regular_price | 24.99 | Regular price. |
Categories | category_ids | Category 1, Category 1 > Category 2 | CSV list of categories. > used for hierarchy. |
Tags | tag_ids | Tag 1, Tag 2 | CSV list of tags. |
Shipping class | shipping_class_id | Name | Name of shipping class |
Images | image_id / gallery_image_ids | http://somewhere.com/image.jpg, http://somewhere.com/image2.jpg | First is featured image. |
Download limit | download_limit | 1 | n/a or a limit. |
Download expiry days | download_expiry | 1 | n/a or a day limit. |
Parent | parent_id | id:100, SKU-1 | Set parent ID. Used for variations. Can be just a numeric ID e.g. id:100 or a SKU. Export will use SKU when possible. |
Grouped products | children | id:100, id:101, SKU-1, SKU-2 | List of IDs. Can be just a numeric ID e.g. id:100 or a SKU. Export will use SKU when possible. |
Upsells | upsell_ids | id:100, id:101, SKU-1, SKU-2 | List of IDs. Can be just a numeric ID e.g. id:100 or a SKU. Export will use SKU when possible. |
Cross-sells | cross_sell_ids | id:100, id:101, SKU-1, SKU-2 | List of IDs. Can be just a numeric ID e.g. id:100 or a SKU. Export will use SKU when possible. |
External URL | product_url | https://mercantile.wordpress.org/product/wordpress-pennant/ | Product external URL. |
Button text | button_text | Buy on the WordPress swag store! | Custom product “buy” button. |
Position | menu_order | 1 | Menu order, used for sorting. |
Attribute 1 name | attributes | Color | Looks for global attribute or uses text if not found. Include as many as needed. “Used for variations” is set automatically. |
Attribute 1 value(s) | attributes | Blue, Red, Green | List of values. Variations only need 1 value. First is used if multiple get provided. |
Attribute 1 default | default_attributes | Blue | Default value for variable products. |
Attribute 1 visible | attributes | 1 | 1 or 0. Mapping screen labels this as “Attribute Visibility” |
Attribute 1 global | attributes | 1 | 1 or 0. Mapping screen labels this as “Is a global attribute?” |
Download 1 name | downloads | Download 1 | |
Download 1 URL | downloads | url.zip |
更多关于Column Header Reference信息请参考官网《Column Header Reference – WooCommerce》。
2. 后台导出
除了在官网下载模板文件外,还有一种方式就是直接在后台下载,前提就是要先在后台上传一个示例产品。

如上图所示,创建了3个示例产品后直接点击左上角的“Export‘导出产品信息文件,然后直接在该文件里进行信息编辑。这么做有一个很大的好处就是这个过程会让你明白更改哪些字段会改变哪些产品信息,这对学习入门很有帮助。
点击“导出”按钮后就会进入产品导出过程。

使用下拉菜单选择导出所有列或选择某一列来导出。

然后使用下拉菜单选择导出所有产品或选择某一个产品类型来导出。

勾选“Export custom meta?”(导出自定义元数据)选项卡,表示你要导出来自其他插件的产品附加信息,元数据列按照上面导入映射部分的meta:前缀标准被导出。默认情况下,不会导出附加元数据。

点击导出后,系统会自动将网站内的信息打包导出为CSV文件。
二、操作步骤
1. 产品创建
首先打开WooCommerce的产品选项卡,选择顶部的“导入”然后进入产品上传流程。

点击“选择文件”选择你的CSV模板文件,通常CSV元素用逗号分隔,如果你在文件中使用不同的分隔符,则可以在“CSV分隔符(高级选项)”进行设置。

下一步进入“列映射”,WooCommerce自动尝试将列名称从你的CSV匹配或映射到数据库字段。

同时你可以在右侧的下拉菜单调整字段或指示不导入,默认情况下不会导入任何无法识别的列。

信息设置完成后,直接选择开始导入,在导入的过程中不要关闭或者刷新页面。
2. 产品更新
产品创建学会了后,产品更新就很简单了。上传的过程都是一样的,唯一不同的是在产品信息文件里使用你想更新的产品的ID和SKU,这样系统在导入的过程中会使用ID和SKU自动匹配并自动更新你在每一行输入的任何信息。
3. 注意事项
首先无论是从后台导出的产品CSV文件还是在官网上下载的CSV模板文件,其内在的编码格式都是UTF-8格式,这也就意味着我们上传产品时使用的文件也必须使用UTF-8编码,否则系统就会报错。
但是我们在电脑上使用办公软件对模板文件进行编辑时,其编码格式会改变,一般Windows电脑编辑后文件编码格式会变成Windows-1252,Mac OS电脑编辑后文件编码格式会变成WebRoman。
所以,为了成功上传产品我们就必须要在文件编辑的过程中注意这一点,推荐使用在线办公软件(Google Sheets)在线上完成产品信息编辑,然后再以CSV文件的格式将其下载下来,直接上传WooCommerce后台,此才能保证没有问题。
其次还需要注意一些细节点:
- 字段中有多个值时需要用英文逗号(,)分隔。
- 导入布尔值(true或false)时要在CSV中使用1或0。
- 图片需要预先上传或在线可用才能导入到你的商店。