Skip to main content

Metafield Data Source Rules

How to use metafield rules in Rebuy Data Sources to personalize product recommendations

Written by Christian Sokolowski

Metafields are a powerful tool for customizing product relationships and recommendations in Rebuy. They allow you to add specific, custom data to your products and set up rules that deliver personalized experiences to your customers. This guide explains how to configure metafields, set up data sources, and utilize them to optimize your product recommendations.


How Metafields Work in Rebuy

Rebuy Data Sources support two distinct metafield rule types. Understanding the difference between them matters because they work differently and serve different use cases.

Value Matching returns products that share the same metafield value as the product being viewed. For example, a rule using custom.color_name returns all products where custom.color_name equals the same value (such as "Red"). Products are grouped by a shared attribute across your catalog. Setup for this rule type is covered in the Metafield Value Matching Rules section below.

Products in Metafield returns specific products you have manually assigned to each product using a list.product_reference metafield in Shopify. Rebuy reads the product references stored on the current product and returns exactly those products, giving you direct editorial control over what appears per product. Setup for this rule type is covered in the Products in Metafield Data Source Rule section below.

Variants in Variant Metafield returns the product tied to a variant you've referenced using a list.variant_reference metafield attached to your product's variants in Shopify. Rebuy reads the referenced variant IDs off the current product's variants, resolves each to its parent product, and returns only the referenced variant(s), not the full product. Setup for this rule type is covered in the Variants in Variant Metafield Data Source Rule section below.

Note: Metafield Data Source rules can read metafields at the product level (Value Matching and Products in Metafield) or the variant level (Variants in Variant Metafield). IF conditions on metafields are still product-level only, using the Product Has Metafield condition. Only the RETURN side supports variant-level values, covered in the Variants in Variant Metafield Data Source Rule section below.


Value Matching Metafield Data Source Rules

The Value Matching metafield rule types returns products that share the same metafield value as the product a customer is currently viewing. Both the current product and the returned products must have the same metafield defined with the same value.

  • Product Has Metafield: Use the "Product Has Metafield" condition and specify the metafield namespace.key you want to match

  • Products with Matching Metafields: Set the RETURN to "Products with Matching Metafields" and enter the namespace.key of the metafield to match on.

How Metafield Value Matching Works

When the rule fires, Rebuy reads the specified metafield on the current product and returns all products in your catalog that share the same value for that metafield.

For example: if you configure a rule using custom.color_name and the current product has custom.color_name = "Red", Rebuy returns all other products where custom.color_name is also "Red."

Steps to Set Up Value Matching in Shopify

Step 1: Define the metafield

  1. Navigate to Settings → Metafields and metaobjects → Products → Add definition in Shopify.

  2. Name the metafield and note the namespace.key it generates (for example, custom.color_name).

Step 2: Add the metafield to products

  1. Go to Products in the main menu and select a product you want to configure.

  2. Scroll down to the Metafields section at the bottom of the product page.

  3. Locate the metafield you created and enter its value (for example, "Bedroom" for custom.home.room).

  4. Repeat for every product that should be grouped together under that value.

Step 3: Sync with Rebuy

Once you have applied the metafield to your products, go to Rebuy Admin and perform a re-sync to update Rebuy with your changes. Allow some time for the sync process to complete. See article Sync Product Data, Store Data, and Clear Cache

Step 4: Set up the rule in Rebuy

Define your Data Source rule using the exact metafield namespace.key (for example, custom.color_name).

Configuring the Value Matching Rule in the Rebuy Data Source Editor

  1. Product Has Metafield: Use the "Product Has Metafield" condition and specify the metafield namespace.key you want to match (for example, custom.color_name or custom.clothing_color).

    [IMAGE example above: Rebuy Data Source editor showing IF: Product Has Metafield → Equals → custom.clothing_color]

  2. Products with Matching Metafields: Set the RETURN to "Products with Matching Metafields" and enter the namespace.key of the metafield to match on. This returns products where the metafield value matches the current product's value.

    [IMAGE example above: Rebuy Data Source editor showing RETURN: Products with Matching Metafields → custom.clothing_color, with arrow pointing to the namespace.key field]

Metafield Value Matching Use Cases

1. Matching Colors

Use a metafield like custom.color_name to categorize products by color. If a customer is viewing a red t-shirt, Rebuy recommends other products with custom.color_name = "Red".

2. Pairing Products

Create a metafield like custom.pair_it_with and assign it a shared value for products meant to be sold together. For example, both a wine glass and a wine bottle could have custom.pair_it_with = "Wine Set", allowing them to be recommended together.


Products in Metafield Data Source Rule

The Products in Metafield rule returns specific products you have manually assigned to each product using a list.product_reference metafield in Shopify. Unlike Value Matching, which groups products by shared values automatically, the Products in Metafield rule returns exactly the products you hand-selected per product.

[IMAGE example above: Black Shirt product page showing the "Complete the Look" add-ons widget with Black Belt, Black Pants, and Black Shoes returned via a Products in Metafield rule]

How Products in Metafield Works

When the rule fires, Rebuy reads the list.product_reference metafield from the current product, resolves the stored product references, and returns those products as the recommendation set. The output is entirely determined by what you assigned in Shopify, not by computed matching or AI.

Important: Although Products in Metafield is a Return rule, it depends entirely on the input product — the product matched by your IF condition — having its metafield values configured in Shopify's product settings. If the metafield is empty or not set on that product in Shopify, Rebuy has no product references to resolve and the widget will output nothing. Every product you intend to use as an input must have the metafield populated in Shopify before the rule can return any results.

Setting Up the Products in Metafield Data Source Rule

Step 1: Create the metafield definition in Shopify

  1. In Shopify Admin, go to Settings → Metafields and metaobjects → Products.

  2. Select Add definition.

  3. Name the metafield (for example, "Complete the look").

  4. Set the type to List, then select Product as the content type.

  5. Under Options, enable Storefront API access. This is required for Rebuy to read the metafield values at query time.

  6. Save the definition. Note the namespace.key (for example, custom.complete_the_look).

[IMAGE example above: Shopify Settings showing the Add product metafield definition screen with name "Complete the look", namespace.key custom.complete_the_look, type List > Product, and Storefront API access toggled on]

Step 2: Populate the metafield on each product

  1. In Shopify Admin, open a product.

  2. Scroll to the Product metafields section at the bottom of the product page.

  3. Locate your metafield and select Select products.

  4. Choose the products you want to recommend alongside this product.

  5. Save the product.

  6. Repeat for every product where you want curated recommendations.

[IMAGE example above: Shopify product page showing the "Complete the look" Product (List) metafield with Black Belt, Black Pants, Black Shirt, Black Shoes, and Black Socks selected]

Step 3: Sync with Rebuy

After populating metafield values, clear the Collections, Metafields, Presentment Prices Cache in Rebuy Admin to ensure Rebuy picks up the new product reference data. Go to Rebuy Admin → Data Sources → Cache Manager.

Step 4: Configure the rule in Rebuy

  1. In the Rebuy Data Source editor, add a rule.

  2. Set the IF condition to match the products you want this rule to apply to. This can be a collection, tag, or any other product condition (for example, Collection → clothes → Contains Any).

  3. Set the RETURN statement to Products In Metafield.

  4. In the dropdown, select the metafield you created. The dropdown is populated from your store's available metafields.

  5. Save the Data Source.

[IMAGE example above: Rebuy Data Source editor showing the full rule using RETURN Products In Metafield → custom.complete_the_look]

Products in Metafield Use Cases

Complete the Look: A dress product's metafield lists the matching shoes, bag, and belt. Every visitor on that product page sees exactly those accessories, with no reliance on shared tags or AI.

Hand-picked cross-sells: Curate specific pairings for products where the relationship doesn't map to a shared attribute.

Editorial control for hero SKUs: Specify exactly what appears alongside your most important products, overriding AI recommendations.

Manually defined product relationships: Pair products that share a use case but no common attribute, such as a coffee maker and a specific compatible filter.

Products in Metafield Limitations

  1. Only works with Shopify's native list.product_reference metafield type (List > Product). Text, integer, and other metafield types are not supported.

  2. Each product's metafield must be populated manually in Shopify's product settings. For large catalogs, a bulk import tool such as Matrixify can populate values at scale.

  3. Storefront API access must be enabled on the metafield definition in Shopify. Without it, Rebuy cannot read the metafield values.

  4. Products referenced in the metafield must be synced to Rebuy to appear in results. A cache clear may be required after adding new values.

  5. Standard product status filtering (Draft, Archived, Unlisted) still applies to referenced products.

  6. If the metafield is not populated on a product in Shopify, the widget rule will not output any products.

  7. This rule reads product-level metafields. For a variant-level reference, use the Variants in Variant Metafield rule.


Variants in Variant Metafield Data Source Rule

The Variants in Variant Metafield rule returns the product tied to a specific variant you've referenced on the input product using a list.variant_reference metafield in Shopify. Unlike Products in Metafield, which references whole products, this rule references individual variants, useful when the relationship you're modeling is variant-specific rather than product-wide.

Variants in Variant Metafield rule returns the product tied to a specific variant you've referenced on the input product using a variant metafield list in Shopify.

How Variants in Variant Metafield Works

When the rule fires, Rebuy reads the list.variant_reference metafield from the variants of the current product (the product matched by your IF condition), resolves each referenced variant to its parent product, and returns those products. The response includes only the variant(s) that were actually referenced, not the full variants array of the returned product.

Important: Like Products in Metafield, this is a RETURN rule that depends entirely on the input product having the metafield populated in Shopify. The metafield must be set on the input product's variant, not the product itself. If none of the input product's variants have the metafield populated, Rebuy has no variant reference to resolve and the widget outputs nothing.

Setting Up the Variants in Variant Metafield Data Source Rule

Step 1: Create the metafield definition in Shopify

  1. In Shopify Admin, go to Settings → Metafields and metaobjects → Variants.

  2. Select Add definition.

  3. Name the metafield (for example, "Related Variant").

  4. Set the type to List, then select Variant as the content type.

  5. Under Options, enable Storefront API access. This is required for Rebuy to read the metafield values at query time.

  6. Save the definition. Note the namespace.key (for example, custom.related_variants).

Step 2: Populate the metafield on each variant

  1. In Shopify Admin, open a product.

  2. Select the specific variant you want to configure.

  3. Scroll to the Metafields section on the variant.

  4. Locate your metafield and select the variant(s) you want to reference.

  5. Save the product.

  6. Repeat for every variant where you want a curated reference.

Step 3: Sync with Rebuy

After populating metafield values, clear the Collections, Metafields, Presentment Prices Cache in Rebuy Admin to ensure Rebuy picks up the new variant reference data. Go to Rebuy Admin → Data Sources → Cache Manager. See article Sync Product Data, Store Data, and Clear Cache.

Step 4: Configure the rule in Rebuy

  1. In the Rebuy Data Source editor, add a rule.

  2. Set the IF condition to match the products you want this rule to apply to.

  3. Set the RETURN statement to Variants In Variant Metafield.

  4. Enter the metafield's namespace.key exactly (for example, custom.related_variants). This field is plain text with no dropdown, so there's no autocomplete or validation against your store's actual metafield definitions. A typo here returns nothing with no visible error.

  5. Save the Data Source.

Variants in Variant Metafield Use Cases

Variant-specific pairing: Reference the exact matching variant of a companion product, for example a specific mug color that pairs with a specific shirt color, rather than pairing at the product level where any color combination would show.

Curated cross-sell down to size or color: Recommend a specific complementary variant (a matching lens color, a specific replacement part SKU) instead of leaving the shopper to find the right one among a full product's variants.

Editorial control at the SKU level: Specify exactly which variant appears alongside a given variant, overriding AI recommendations for cases where the relationship is too specific for a shared attribute or tag to capture.

Gift-with-purchase by variant: A skincare brand wants a specific sample-size variant of its face oil to appear as a gift-with-purchase item when a customer has a qualifying product, such as a moisturizer, in their cart. The face oil's sample variant is referenced in a list.variant_reference metafield, and the IF condition matches on the moisturizer being present in the cart. The RETURN resolves to the sample variant specifically, not the full-size face oil product.

Variants in Variant Metafield Limitations

  1. Only works with Shopify's native list.variant_reference metafield type (List > Variant). Text, integer, other metafield types, and list.product_reference are not supported.

  2. The metafield must be populated on the specific variant in Shopify, not on the product itself.

  3. Storefront API access must be enabled on the metafield definition in Shopify. Without it, Rebuy cannot read the metafield values.

  4. Only the referenced variant(s) are included in the response. The rest of the returned product's variants are trimmed out, so a widget or template expecting a full variants array will see a partial product.

  5. The namespace.key field is plain text with no dropdown or autocomplete. There's no picker validating it against your store's actual metafield definitions.

  6. Referenced variants must belong to products synced to Rebuy to appear in results. A cache clear may be required after adding new values.

  7. Standard product status filtering (Draft, Archived, Unlisted) still applies, and products not published to the Online Store sales channel are always excluded from this rule's output, regardless of the "Filter unpublished products" checkbox.

  8. This rule type is RETURN-only. There's no corresponding IF condition for variant-level metafields; Product Has Metafield still evaluates product-level metafields only.


Tips for Effective Use of Metafields

  1. Minimize rule complexity: Use metafields to group products efficiently, reducing the need for multiple individual rules.

  2. Strategic value assignments: Assign metafield values based on logical groupings like color, category, or complementary use cases.

  3. Choose descriptive values: Use intuitive and meaningful metafield values (for example, "holiday-set") to clearly define product groupings.

  4. Plan your metafield structures: Develop a metafield strategy ahead of time to maintain consistency and align with your data management goals.

  5. Use an AI fallback: Add an AI endpoint (such as Recommended AI) as the last rule in any Data Source that uses metafield rules. If the metafield is empty or unpopulated on a product, the AI rule ensures the widget always returns products.

  6. Verify in Rebuy: Regularly check metafield value accuracy within Rebuy's admin interface to confirm metafield types and values are set up correctly.


Frequently Asked Questions About Metafield Data Source Rules

This section covers common questions and issues merchants encounter when configuring metafield rules in Rebuy Data Sources. Each answer addresses a specific behavior or setup challenge that affects how metafield rules return and display products.

Why are products not being recommended as expected?

Metafield rules in Rebuy return no results when the namespace.key in the rule does not match the metafield definition in Shopify exactly, or when the metafield values are not yet synced to Rebuy. Confirm the namespace.key matches, then clear the Collections, Metafields, Presentment Prices Cache in Rebuy Admin and reload the widget preview. For Products in Metafield, also verify the correct products are selected on the product page in Shopify.

Why is only one product being recommended with the Value Matching rule?

The Value Matching rule only returns products that share the same metafield value as the current product. If only one product is appearing, the metafield value on that product may be unique to it. Use a value that is shared across multiple products (for example, custom.color_name = "Red" assigned to several products). Avoid unique metafield values that don't group products effectively.

Why is my Products in Metafield rule returning no results?

The Products in Metafield rule returns nothing when the input product — the product matched by the IF condition — does not have the metafield populated in Shopify's product settings. Rebuy has no product references to resolve, so the widget outputs nothing. Open the product in Shopify Admin, scroll to Product metafields, and confirm the metafield has products selected. Also verify that Storefront API access is enabled on the metafield definition. After making changes, clear the Collections, Metafields, Presentment Prices Cache in Rebuy Admin.

Do metafield Data Source rules support variant-level metafield values?

Yes, on the RETURN side. The Variants in Variant Metafield rule reads a list.variant_reference metafield from the input product's variants and returns the specific referenced variant(s). Data Source "IF" conditions on metafields are evaluated at the product level, so Product Has Metafield doesn't support variant-level values.

Did this answer your question?