fervor [>]CODING & CURIOSITY
FERVOR LEARNING SYSTEMTUTORIALS
← WordPress

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

  1. 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.
  2. Save the CSV
    Save the file in .csv format. 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

  1. 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.
  2. 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.

PART 3: Importing Your CSV

  1. Upload the CSV

    • Open your plugin (e.g., Product Import Export for WooCommerce).
    • Select your CSV file and click Next.
  2. Map CSV Columns to WooCommerce Fields

    • The plugin will ask you to match your CSV columns to WooCommerce fields.
    • For example:
      • Name → Product Name
      • Price → Regular Price
      • Stock → Stock Quantity
      • _andover_wavelength_value → Custom Field (this might require a small tweak—see Part 4).
  3. 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)

  1. Understand What Custom Fields Are

    • Custom fields are extra data fields WooCommerce stores for products. They are also called meta fields.
    • _andover_wavelength_value is an example of a custom field used to store wavelengths.
  2. 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.
  3. Add Custom Fields Programmatically (Advanced)
    If you want to make _andover_wavelength_value appear automatically during import:

    • Use WooCommerce hooks in your theme’s functions.php file:
      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.
  4. View Custom Fields

    • After import, custom fields like _andover_wavelength_value can be seen in:
      • Products > Edit Product > Custom Fields.

PART 5: Displaying Custom Fields on the Frontend

  1. Modify the Product Template
    To display _andover_wavelength_value on 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>';
      }
      ?>
      
  2. 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! 🚀

Keep your curiosity going.Explore more WordPress →
287 TUTORIALS · 22 TOPICSREADY