Migrate Product Reviews to Shopify: Keep the Stars

Shopify has no built-in store for product reviews, so you migrate product reviews to Shopify in two parts. The review text goes into whichever review app you pick, through that app’s importer. The star average and count go into the standard reviews.rating and reviews.rating_count metafields, which is what themes like Dawn read to draw stars.

It is easy to do only the first part and assume the app handles the second. Sometimes it does. When it does not, the stars on collection pages disagree with the reviews on product pages, or vanish for every product the app’s importer could not pair, and nothing in the admin flags it. This post covers both halves for a WooCommerce source, written against Admin GraphQL 2026-10 (the latest stable version on Shopify’s versioning page as of November 2026).

Where do reviews live on Shopify?

In an app. Shopify itself stores the aggregate, not the reviews. The list of standard metafield definitions defines two in the reviews namespace, both on products and variants:

  • reviews.rating, type rating, “the average rating for a product or variant”
  • reviews.rating_count, type number_integer, “the total number of ratings”

Shopify’s guidance is that “product rating apps should write to this standard metafield”, and that themes showing ratings should read it. Dawn does exactly that: snippets/card-product.liquid and the rating block in sections/main-product.liquid check product.metafields.reviews.rating.value and print nothing if it is blank. So a product with 40 imported reviews and an empty metafield shows no stars on the collection grid, even while the app’s widget lists every review further down the page.

The rating type is a JSON object, and per the data types reference every part of it is a string:

{ "value": "4.5", "scale_min": "1.0", "scale_max": "5.0" }

How do you export reviews from WooCommerce?

Through the REST API’s product reviews endpoint, GET /wp-json/wc/v3/products/reviews. Each review carries product_id, status, reviewer, reviewer_email, review (the text), rating and verified, the flag for whether the reviewer bought the product.

Three details decide whether your numbers come out right.

The status filter defaults to approved, which is what you want. Held and spam reviews should not cross over, and status=all would bring them along. We pass status=approved explicitly anyway so the intent is visible in the code.

The API documents rating as 0 to 5. A 0 means a text review with no stars, which happens when the shop does not require a rating. WooCommerce’s own average skips them: get_average_rating_for_product() in class-wc-comments.php filters on meta_value > 0 and approved comments only. Count those zeros into your average and every product with a few text-only reviews can drop by a star or more.

Pagination defaults to 10 per page. WordPress caps per_page at 100 (REST API handbook) and returns the page count in the X-WP-TotalPages header, so loop on that rather than stopping at the first short page.

WooCommerce also exposes average_rating and rating_count directly on each product. We use those as a cross-check, not as the source. They are stored values on the old site, and the number you publish on Shopify should come from the exact set of reviews you are importing, so the stars and the visible reviews agree.

How do you set reviews.rating with the Admin API?

Enable the two standard definitions first, so a type problem fails before you write a few thousand values. Shopify says standard definitions auto-enable when an app writes values to them, but enabling them yourself lets you read back the validations and match your scale to them:

mutation EnableReviewDefinitions {
  rating: standardMetafieldDefinitionEnable(namespace: "reviews", key: "rating", ownerType: PRODUCT) {
    createdDefinition { id type { name } validations { name value } }
    userErrors { field message code }
  }
  count: standardMetafieldDefinitionEnable(namespace: "reviews", key: "rating_count", ownerType: PRODUCT) {
    createdDefinition { id type { name } }
    userErrors { field message code }
  }
}

If a review app got there first, the definitions may already exist. Read userErrors before assuming the call created anything.

Then the script. It pulls every approved WooCommerce review, averages the rated ones per product, maps WooCommerce product IDs to Shopify product GIDs and writes both metafields with metafieldsSet. The ID map is the woo-to-shopify.json file your catalogue import should already produce; if it did not, our WooCommerce catalogue mapping post covers building one.

// reviews-to-shopify.mts: run with `node reviews-to-shopify.mts` (Node 24+)
import { readFile } from 'node:fs/promises';

type WooReview = { id: number; product_id: number; rating: number; status: string };
type Aggregate = { sum: number; count: number };

const WOO = process.env.WOO_URL!; // https://old-shop.example
const WOO_AUTH = Buffer.from(`${process.env.WOO_KEY}:${process.env.WOO_SECRET}`).toString('base64');
const SHOP = process.env.SHOP!; // your-store.myshopify.com
const TOKEN = process.env.SHOPIFY_ADMIN_TOKEN!;
const DRY_RUN = process.env.DRY_RUN === '1';

// Woo product ID -> Shopify product GID, written by your catalogue import.
const idMap: Record<string, string> = JSON.parse(await readFile('woo-to-shopify.json', 'utf8'));

async function fetchApprovedReviews(): Promise<WooReview[]> {
  const all: WooReview[] = [];
  for (let page = 1, totalPages = 1; page <= totalPages; page++) {
    const url = `${WOO}/wp-json/wc/v3/products/reviews?status=approved&per_page=100&page=${page}`;
    const res = await fetch(url, { headers: { Authorization: `Basic ${WOO_AUTH}` } });
    if (!res.ok) throw new Error(`Woo ${res.status} on page ${page}`);
    totalPages = Number(res.headers.get('X-WP-TotalPages') ?? '1');
    all.push(...((await res.json()) as WooReview[]));
  }
  return all;
}

function aggregate(reviews: WooReview[]): Map<number, Aggregate> {
  const byProduct = new Map<number, Aggregate>();
  for (const r of reviews) {
    if (r.rating < 1) continue; // 0 = text-only review; WooCommerce skips these too
    const agg = byProduct.get(r.product_id) ?? { sum: 0, count: 0 };
    agg.sum += r.rating;
    agg.count += 1;
    byProduct.set(r.product_id, agg);
  }
  return byProduct;
}

const SET = `mutation SetRatings($metafields: [MetafieldsSetInput!]!) {
  metafieldsSet(metafields: $metafields) {
    metafields { key owner { ... on Product { handle } } }
    userErrors { field message code elementIndex }
  }
}`;

async function setBatch(metafields: object[]): Promise<void> {
  const res = await fetch(`https://${SHOP}/admin/api/2026-10/graphql.json`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json', 'X-Shopify-Access-Token': TOKEN },
    body: JSON.stringify({ query: SET, variables: { metafields } }),
  });
  const body = await res.json();
  const errors = body.errors ?? body.data?.metafieldsSet?.userErrors ?? [];
  if (!res.ok || errors.length) throw new Error(JSON.stringify(errors));
}

const aggregates = aggregate(await fetchApprovedReviews());
const inputs: object[] = [];
for (const [wooId, { sum, count }] of aggregates) {
  const ownerId = idMap[String(wooId)];
  if (!ownerId) {
    console.warn(`No Shopify product for Woo product ${wooId}, skipping`);
    continue;
  }
  const rating = { value: (sum / count).toFixed(1), scale_min: '1.0', scale_max: '5.0' };
  inputs.push(
    { ownerId, namespace: 'reviews', key: 'rating', type: 'rating', value: JSON.stringify(rating) },
    { ownerId, namespace: 'reviews', key: 'rating_count', type: 'number_integer', value: String(count) },
  );
}

// metafieldsSet takes at most 25 inputs; 24 keeps each product's pair together.
for (let i = 0; i < inputs.length; i += 24) {
  const batch = inputs.slice(i, i + 24);
  if (DRY_RUN) console.log(JSON.stringify(batch, null, 2));
  else await setBatch(batch);
}
console.log(`${aggregates.size} products with ratings, ${inputs.length / 2} mapped`);

metafieldsSet takes at most 25 metafields per call and is atomic, so one bad value rejects the whole batch. Batching in 24 keeps each product’s rating and count in the same call, which means a failure never leaves a product with a count but no average. The script throws on the first error with the userErrors array, including elementIndex, so you can find the offending product. Our metafieldsSet write-up goes further into batching and compareDigest if the review app may be writing at the same time.

Run it with DRY_RUN=1 first and read a few batches. The .mts extension matters: Node 24 strips the types and runs it directly, and the extension tells Node to treat the file as an ES module, which the top-level await needs.

Rating is written at product level only. WooCommerce reviews belong to the parent product, not a variation, so there is nothing honest to put on variants.

Who owns the metafield after cutover?

Decide this before you run anything. Shopify asks rating apps to update reviews.rating whenever a product’s rating changes, and an app can only calculate from the reviews it holds. If its import matched 900 of your 1,000 products, the next new review on any of the missing 100 can replace your migrated average with an average of one.

So the order we use is: import the review bodies into the app, let it compute, then compare. That turns our script into an audit tool. Keep its fetch and aggregate steps, swap the write for this read, and diff the two:

query CheckRatings($ids: [ID!]!) {
  nodes(ids: $ids) {
    ... on Product {
      handle
      rating: metafield(namespace: "reviews", key: "rating") { jsonValue }
      count: metafield(namespace: "reviews", key: "rating_count") { value }
    }
  }
}

Any product where Shopify’s count is lower than your WooCommerce count has reviews the app did not import, often because the handle or SKU changed during migration and that is what the app’s importer matches on. Fix the mapping in the app’s CSV and re-import those products. Only write the metafields yourself if you are launching without a review app, or you have confirmed the app leaves alone the products it holds no reviews for.

What happens to review structured data?

Google’s review snippet guidelines say that if you use AggregateRating, “users should be able to see that aggregate rating on the page”, and they forbid aggregating ratings from other websites. Migrated reviews from your own old shop are your reviews, so importing them is fine. Publishing an average from 40 reviews while the page shows none of them is not.

Shopify’s structured_data filter documents its Product output without any rating, and a review app may add its own JSON-LD. Check the rendered page for two aggregateRating blocks, one from the app and one from a theme snippet someone added during the build. Our post on finding duplicate structured data in Liquid shows how to spot them.

Personal data comes along too. reviewer_email is in every review the API returns, and in the CSV you build for the app’s importer, so keep that file out of shared drives and delete it once the import is confirmed.

What we would do

Pick the review app before the catalogue import, so you know its CSV format and how it matches products. Run the script above in dry-run mode to get the expected averages and counts, import the review bodies into the app, then use the check query to diff Shopify’s counts against WooCommerce’s for every product. Write the metafields directly only when there is no app yet. Run the diff even when the app’s import screen reports success, because a product the importer could not match simply has no reviews in the app, and there is nothing for that screen to report.

Moving reviews is one of the jobs we handle as part of a WooCommerce or Magento move. If you want the catalogue, reviews and redirects done as one migration, that is our Shopify development work.

Need this built properly?

Get in touch

Hack the planet!