Importing product reviews into WooCommerce can enhance customer trust, especially when migrating from another store or restoring backed-up reviews. While many plugins are available for this purpose, importing reviews manually offers complete control over the process. This post ties in with our previous post on how to export WooCommerce reviews by demonstrating how to import reviews from CSV or XML files without a plugin.
Why Import WooCommerce Reviews?
Here are a few reasons why you might want to import reviews:
- Store Migration: Move customer reviews from another platform or website to WooCommerce.
- Restore Backups: Re-import reviews from saved backups to recover lost data.
- Enhance Product Pages: Add pre-existing reviews to new products to build trust with customers.
Step 1: Prepare Your CSV or XML File
Before importing, ensure your reviews are formatted correctly. If you’ve exported your reviews as CSV or XML following the instructions in our export reviews guide, the file will already be in the right format.
CSV headers should look like this:
- Product ID
- Author
- Review
- Date
- Approved
Step 2: Add Code to Import Reviews from CSV
The following code allows you to import reviews from a CSV file. Add this snippet to your theme’s functions.php file or a child theme.
/* Snippet: How to Import WooCommerce Reviews Without a Plugin – 2025
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1617
* Tested with WooCommerce 9.3.3
* “This function imports reviews into WooCommerce from a CSV file”
*/
function wcsuccess_import_reviews_from_csv( $file_path ) {
if ( ! file_exists( $file_path ) ) {
wp_die( ‘File not found!’ );
}$csv = fopen( $file_path, ‘r’ );
fgetcsv( $csv ); // Skip the header rowwhile ( ( $row = fgetcsv( $csv ) ) !== false ) {
$comment_data = array(
‘comment_post_ID’ => $row[0], // Product ID
‘comment_author’ => $row[1], // Author
‘comment_content’ => $row[2], // Review content
‘comment_date’ => $row[3], // Date
‘comment_approved’ => $row[4] === ‘Yes’ ? 1 : 0, // Approved status
‘comment_type’ => ‘review’,
);
wp_insert_comment( $comment_data );
}fclose( $csv );
}
How This Works
- File Handling: The code reads the CSV file row by row, skipping the header.
- Comment Data: Each row is mapped to a WooCommerce review and imported using wp_insert_comment().
To trigger the import, call the function in your code:
wcsuccess_import_reviews_from_csv( ‘path/to/your-file.csv’ );
Step 3: Import Reviews from XML
If your reviews are in XML format, use the following code to import them:
/* Snippet: How to Import WooCommerce Reviews Without a Plugin – 2025
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1617
* Tested with WooCommerce 9.3.3
* “This function imports WooCommerce reviews from an XML file”
*/
function wcsuccess_import_reviews_from_xml( $file_path ) {
if ( ! file_exists( $file_path ) ) {
wp_die( ‘File not found!’ );
}$xml = simplexml_load_file( $file_path );foreach ( $xml->Review as $review ) {
$comment_data = array(
‘comment_post_ID’ => (int) $review->ProductID,
‘comment_author’ => (string) $review->Author,
‘comment_content’ => (string) $review->Content,
‘comment_date’ => (string) $review->Date,
‘comment_approved’ => (string) $review->Approved === ‘Yes’ ? 1 : 0,
‘comment_type’ => ‘review’,
);
wp_insert_comment( $comment_data );
}
}
How This Works
- XML Parsing: The code reads the XML file and maps each review to a WooCommerce product.
- Comment Import: The wp_insert_comment() function inserts each review into the WooCommerce system.
To trigger the import, call the function:
wcsuccess_import_reviews_from_xml( ‘path/to/your-file.xml’ );
Note : Replace ‘path/to/your-file.xml’ with the path to your XML file.
Step 4: Verify the Imported Reviews
After importing, visit the Products > Reviews section in your WooCommerce dashboard to verify the imported reviews. Make sure all reviews are associated with the correct products and display properly.
Best Use Cases for Importing Reviews
- Migrate Reviews from Another Platform: Transfer reviews seamlessly to your WooCommerce store.
- Restore from Backup: Re-import reviews after data loss or a site migration.
- Populate New Products with Reviews: Add reviews to new products to increase customer trust.
Conclusion
Importing WooCommerce reviews without a plugin offers complete control over the data and eliminates the need for additional tools. Whether you’re migrating, restoring, or simply enhancing your product pages, these code snippets help you manage reviews efficiently.
Make sure to test these changes in a staging environment before applying them to your live site. For more customizations, explore our wp-config generator to streamline your WordPress setup.
This guide complements our guide on how to export WooCommerce reviews without a plugin