WordPress / 4 MIN READ
Import CSV Woo 102
Importing CSV into WooCommerce for product mapping
From the original Fervor library. Examples may use older package versions.
Let’s dive into importing a CSV into WooCommerce for product mapping and adding custom fields like _andover_wavelength_value. We’ll break it into manageable steps so you can master it with ease. 🛠️✨
PART 1: Preparing Your CSV File
-
Create a Properly Formatted CSV
Your CSV should include columns for all the data you want to map into WooCommerce. Here’s a simple example structure:SKU Name Price Stock _andover_wavelength_value 12345 Red Laser 199.99 10 650 nm 67890 Green Laser 249.99 5 532 nm - SKU: A unique identifier for your product.
- Name: The product name.
- Price: Product price.
- Stock: How many you have in inventory.
- _andover_wavelength_value: A custom field we’re adding to track wavelength.
-
Save the CSV
Save the file in.csvformat. Ensure it’s UTF-8 encoded (most spreadsheet tools like Excel or Google Sheets have this option when saving).
PART 2: Installing a WooCommerce Import Plugin
-
Install a CSV Import Plugin
- Go to your WordPress dashboard:
Plugins > Add New. - Search for Product Import Export for WooCommerce (popular free plugin) or a premium alternative like WP All Import.
- Install and activate the plugin.
- Go to your WordPress dashboard:
-
Check WooCommerce’s Built-In Importer (Optional)
If you don’t want to use a plugin, WooCommerce also includes a basic CSV importer:- Go to:
WooCommerce > Products. - Click the Import button at the top.
- It supports CSV imports but lacks advanced mapping features.
- Go to:
PART 3: Importing Your CSV
-
Upload the CSV
- Open your plugin (e.g.,
Product Import Export for WooCommerce). - Select your CSV file and click Next.
- Open your plugin (e.g.,
-
Map CSV Columns to WooCommerce Fields
- The plugin will ask you to match your CSV columns to WooCommerce fields.
- For example:
Name→ Product NamePrice→ Regular PriceStock→ Stock Quantity_andover_wavelength_value→ Custom Field (this might require a small tweak—see Part 4).
-
Confirm & Import
- Review the mapping and start the import.
- The plugin will add products to WooCommerce, including stock levels and custom fields.
PART 4: Adding Custom Fields (e.g., _andover_wavelength_value)
-
Understand What Custom Fields Are
- Custom fields are extra data fields WooCommerce stores for products. They are also called meta fields.
_andover_wavelength_valueis an example of a custom field used to store wavelengths.
-
Enable Custom Fields Display (Optional for Testing)
- In WordPress, custom fields might not show by default. Enable them in the Product Edit screen:
- Go to:
Products > Edit Product. - Click Screen Options (top-right corner).
- Check the box for Custom Fields.
- Go to:
- In WordPress, custom fields might not show by default. Enable them in the Product Edit screen:
-
Add Custom Fields Programmatically (Advanced)
If you want to make_andover_wavelength_valueappear automatically during import:- Use WooCommerce hooks in your theme’s
functions.phpfile:add_action('woocommerce_product_import_inserted_product_object', 'add_custom_field', 10, 2); function add_custom_field($product, $data) { if (!empty($data['_andover_wavelength_value'])) { $product->update_meta_data('_andover_wavelength_value', $data['_andover_wavelength_value']); } } - This snippet ensures WooCommerce recognizes and saves the custom field when importing.
- Use WooCommerce hooks in your theme’s
-
View Custom Fields
- After import, custom fields like
_andover_wavelength_valuecan be seen in:Products > Edit Product > Custom Fields.
- After import, custom fields like
PART 5: Displaying Custom Fields on the Frontend
-
Modify the Product Template
To display_andover_wavelength_valueon product pages:- Edit your theme files (preferably via a child theme).
- Add this to
single-product.php:<?php $wavelength = get_post_meta(get_the_ID(), '_andover_wavelength_value', true); if ($wavelength) { echo '<p>Wavelength: ' . esc_html($wavelength) . '</p>'; } ?>
-
Use a Page Builder or Shortcode
- If you’re using Elementor or a similar page builder, you can dynamically pull custom fields into the layout.
- Some plugins, like Advanced Custom Fields (ACF), allow you to use shortcodes to display custom fields.
Tips for Success
-
Test Your CSV on a Staging Site
Before importing into a live site, test on a staging version of your site to ensure everything maps correctly. -
Validate the CSV Format
Double-check that your CSV has no empty rows, mismatched columns, or invalid characters. -
Leverage Documentation
Plugins like WP All Import have detailed documentation for advanced custom field mapping.
You’re ready to import CSVs like a pro! 🚀