Skip to content

Product rules per customer group

Applies toShopifyBigCommerceWooCommerceMagento

Steps for

How it works

Customers in each group see the product with their group's rules, for example a pack size of 50 instead of 1 in the quantity selector.

Behind this is a metafield: an extra field on a product or variant in your eCommerce platform's admin. SparkLayer reads the sparklayer.settings metafield on each product variant. Its value is a list with one entry per customer group. Each entry names the group and the settings that apply to it:

[
    {
        "customer_group": "gold-tier",
        "min_order_quantity": 5,
        "max_order_quantity": 50
    }
]

The base entry is the default for every customer group. An entry for a specific group, such as influencer, overrides it for that group. You only need to include the settings you want to set. See Which rule wins.

To set a rule for all customers without customer groups, you can use the individual metafields instead, such as sparklayer.pack_size in Quantity rules or sparklayer.reserve_stock_quantity in Stock display. Don't combine the two on one variant: when a variant has a sparklayer.settings value, it takes priority over the individual metafields.

Before you start: turn the metafield on in SparkLayer

SparkLayer doesn't read a metafield until it's enabled in SparkLayer. Go to Integrations,Platform (opens in your SparkLayer Dashboard in a new tab) and, in the Metafields card, click Configure next to SparkLayer metafields, then enable the product settings metafield. If you create the definition yourself in Shopify, it must read exactly sparklayer.settings, with the type JSON, on Variants. See Common mistake: wrong namespace.

Which rule wins

When SparkLayer works out a customer's rules for a variant, it checks in this order:

  1. The customer's group entry in sparklayer.settings, if there is one. Its settings override the base entry.
  2. The base entry in sparklayer.settings. It's the default for every customer group, including groups that have no entry of their own.
  3. The individual metafields, such as sparklayer.pack_size or sparklayer.max_order_quantity, but only when the variant has no sparklayer.settings value at all.

So if you use sparklayer.settings to hide a product from one group, and you also want a pack size or a maximum quantity, put those keys in the JSON too, inside each group's entry. Don't rely on the individual metafields for them.

For example, this value on a variant:

[
  { "customer_group": "base", "pack_size": 50 },
  { "customer_group": "retail-partners", "pack_size": 10, "display": true },
  { "customer_group": "distributors", "display": false }
]
Customer groupWhat its customers get
Base, and every group with no entry of its ownThe product, in packs of 50
retail-partnersThe product, in packs of 10
distributorsThe product is hidden

If the same variant also had sparklayer.pack_size set to 6, nobody would see packs of 6: the sparklayer.settings value wins.

Quantity pricing can set a minimum too. The lowest quantity tier in the customer's price list is the smallest quantity they can order. If the first tier is 50+, customers can't order fewer than 50 and may see "Unavailable in selected quantity". Add a tier from 1 to fix it. See Quantity pricing.

What hides what

display: false in sparklayer.settings hides a product inside SparkLayer's own views. Hiding it from your Shopify theme's pages needs the free B2B Catalogs app as well.

Variant rules don't hide anything from retail shoppers. sparklayer.settings rules only apply to signed-in B2B customers, by customer group. Retail shoppers and signed-out visitors see every variant your theme shows, and Shopify can't hide a single variant of a product from them. To keep one variant for B2B customers only, such as a 12-pack case, make it a separate product. On Shopify, tag that product b2b-only with B2B Catalogs.

Shopify only

What you useSparkLayer's views (search, quick order, quick buy, cart)Collection and search pagesProduct pageFeatured sections
display: false in sparklayer.settingsHiddenStill shownStill opens. SparkLayer's product interface leaves the variant outStill shown
b2b-only or b2c-only product tag, with B2B CatalogsNot hiddenHiddenAccess denied pageHidden
Catalogs per customer group: display: false for a group, with B2B CatalogsHiddenHiddenAccess denied pageHidden
Things to check when a product isn't hidden
  • B2B Catalogs must be enabled on your live theme. The b2b-only and b2c-only tags only work when the app is installed and enabled on your published theme. See Enable or disable it on other themes.
  • After an app update or a theme change, if b2b-only products appear in a section such as a featured collection, disable B2B Catalogs on the live theme and enable it again. Disabling removes your changes to the access denied page, so keep a copy first.
  • The JSON uses straight quotes ("). Curly quotes (“ ”), which word processors add, stop the value working. Build it with the form to be safe.
  • A whole collection can't be hidden. B2B Catalogs hides products, not collections. A third-party Shopify app can restrict who can open a collection's URL.
  • Collection pages, search and filter counts. Hiding happens in your theme as the page loads, so a hidden product can still take a place in a collection grid and count towards product and filter totals. See Collection grids, search and filter counts.

To show a product to everyone but its price only to some customers ("price on application"), see Price on application.

Example: a product range for each customer group

A supplier sells to retail shoppers, salons and stockists from one Shopify store. Salons should see the professional range, stockists the retail-pack range, and retail shoppers neither.

  1. Tag every product in both ranges b2b-only, so retail shoppers and signed-out visitors don't see them.

  2. On each variant in the professional range, set sparklayer.settings to show it only to the salons group:

    [
      { "customer_group": "base", "display": false },
      { "customer_group": "salons", "display": true }
    ]
  3. On each variant in the retail-pack range, do the same for the stockists group:

    [
      { "customer_group": "base", "display": false },
      { "customer_group": "stockists", "display": true }
    ]
WhoProfessional rangeRetail-pack rangeEverything else
Retail shoppers and signed-out visitorsHidden (b2b-only)Hidden (b2b-only)Shown
Customers tagged b2b-salonsShownHiddenShown
Customers tagged b2b-stockistsHiddenShownShown
Any other B2B customerHiddenHiddenShown

Rules are per customer group, not per customer. To give one customer their own range, put them in a group of their own. Build each value with the form, which also shows how to fill in many variants at once.

Set product settings for a customer group

Create the metafield definition

You only do this once. It adds the sparklayer.settings field to every variant.

More detail

Find the customer group's handle

Go to Customers,Groups (opens in your SparkLayer Dashboard in a new tab), click the group's name and find its Handle (or ID), for example base for the base customer group or vip for a group with the handle vip. The group's Shopify tag is b2b- followed by the handle. In the metafield, always write it in lowercase. See Customer groups for how handles work.

Build the value and add it to the variant

Fill in the form below: one entry per customer group, with only the settings you want. It writes the value for you. Click Copy, then open the product variant in your platform's admin, paste the value into the sparklayer.settings field and save the variant.

Build the value Fill in what you need and leave the rest blank.
Customer group 1
Paste into sparklayer.settings
Fill in a value above

Lots of products? Fill them in one tableShopify

In your Shopify admin, go to Products, tick the products and click Edit products. Click Columns, tick the SparkLayer field under Metafields, then type the values (each variant has its own row) and click Save. Shopify's guide

Examples

Exclusive products for one group

Company X has 2 customer groups:

  1. Base: standard B2B customers
  2. Gold tier: preferred customers with discounted pricing and access to exclusive products

To make a range exclusive to Gold tier, they add this to the exclusive variants:

[
    {
        "customer_group": "base",
        "display": false,
        "sell": false
    },
    {
        "customer_group": "gold-tier",
        "display": true,
        "sell": true
    }
]

The base entry hides the variants from every group, and the gold-tier entry overrides it, so these variants are now only visible to Gold tier customers. Variants with no sparklayer.settings value stay visible to everyone, so the rest of the catalogue needs nothing.

Different pack sizes for each group

Company X has 2 customer groups:

  1. Wholesale: other businesses that stock their products, who order large quantities
  2. Influencer: people who promote their products on social media, who only need single units

To sell in packs of 50 to wholesale customers and singly to influencers, they use:

[
    {
        "customer_group":"base",
        "pack_size":50
    },
    {
        "customer_group":"influencer",
        "pack_size":1
    }
]

The base entry applies to all customer groups. The second entry gives the influencer group a pack size of 1.

Available product settings

You can set any of these for a customer group:

SettingTypeWhat it doesDefault
customer_groupstringThe customer group the settings apply to. Required in every entry.
pack_sizeinteger or nullOnly allow the product to be bought in multiples of this number.1
reserve_stock_quantityinteger or nullAlways keep this much stock back, usually so retail (DTC) customers can still buy it.null
min_order_quantityinteger or nullOnly allow the product to be bought in at least this quantity.null
max_order_quantityinteger or nullOnly allow the product to be bought in at most this quantity.null
min_order_parent_quantityinteger or nullMinimum quantity across all of the product's variants.null
max_order_parent_quantityinteger or nullMaximum quantity across all of the product's variants.null
displayboolean or nullWhether the product shows in the frontend interfaces.null
sellboolean or nullWhether the product can be added to the cart.null

Metafield reference

Use these values if you create the metafield definition yourself:

FieldValue
Custom data typeVariants (Shopify (opens in a new tab))
Metafield typeJSON
Namespacesparklayer
Keysettings
ValueA list of entries, for example:
[{"customer_group": "base","pack_size": 1,"reserve_stock_quantity": 10,"min_order_quantity": 5,"max_order_quantity": 50,"min_order_parent_quantity": 5,"max_order_parent_quantity": 50,"display": true,"sell": true}]

Troubleshooting

FAQs

Was this page helpful?

Last updated