Skip to main content

How to conditionally load Rebuy for certain users or on specific themes only

A guide for choosing where Rebuy is installed and which customers can access Rebuy features.

Written by Diana Ibarra
Updated this week

Some merchants need the ability to disable Rebuy for certain customers or to only load Rebuy on certain themes. This guide will show how you can achieve both of these goals. To begin, follow the first part of this help doc for toggling off Rebuy JS from within the Rebuy Admin.


Loading Rebuy only for specific customers or user groups

Disabling the automatic Rebuy script tag

Before adding the conditional script, you need to turn off Rebuy's automatic loading in your Rebuy Admin settings here: rebuyengine.com/settings. Without this step, Rebuy will continue to load on all themes regardless of the code you add to theme.liquid.

Step 1: Open the theme.liquid file in Shopify Admin

To conditionally load Rebuy for specific customers, start by opening the theme.liquid file in your Shopify Admin.

After logging into the Shopify Admin for your store, open the specific theme you're working in and search for the theme.liquid file. This is the file we'll be working in, next scroll down until you locate the closing body tag </body>. In the code editor, use Cmd+F (Mac) or Ctrl+F (Windows) to search for </body>. The tag appears near the very bottom of the file, usually within the last 10–20 lines.

Step 2: Add the conditional Rebuy script for specific customers

If you'd like to block Rebuy for certain customers, you'll first need to tag those customers with a common tag. Example: 'wholesale"

Then you can copy and paste the code below into your theme.liquid file, just above the closing body tag </body>.

{% unless customer.tags contains 'insert tag here' %}

<script async src="https://cdn.rebuyengine.com/onsite/js/rebuy.js?shop={{ shop.permanent_domain }}"></script>

{% endunless %}

Update the first line to replace 'insert tag here' with the actual customer tag you're using. For example, if your tag is wholesale, the first line should read:

{% unless customer.tags contains 'wholesale' %}

Note: This code loads Rebuy only for customers who do not have that tag. Any customer with the tag assigned will see your store without Rebuy features.

Important: App Blocks will still load Rebuy even after disabling the script tag

If you're using App Blocks to install Rebuy widgets, removing the automatic script tag alone won't stop Rebuy from loading. App Blocks load Rebuy independently. To fully control when Rebuy loads, you have two options:

  • Remove your App Block placements and manually install your widgets in your theme files instead


Loading Rebuy on specific themes only

This is useful for merchants who want to test Rebuy on a draft or staging theme before rolling out to their live storefront.

Tip: Before going through the manual script tag setup below, consider using Rebuy's Storefront Preview Mode instead. You can keep widgets toggled off in live mode and preview them on your live store and draft theme's with no code changes required.

If you do need Rebuy to load on a specific theme only, follow these steps.

Step 1: Disable the automatic Rebuy script tag

  1. Go to Rebuy Settings: rebuyengine.com/settings

  2. Toggle OFF "Install Rebuy Script Tag and Disable Rebuy JS"

  3. In the dropdown below, set "Enable Rebuy JS" to No

  4. Click Save

This removes Rebuy from loading automatically across all themes.

Step 2: Add the Rebuy script to your target theme

  1. In Shopify Admin, open the theme.liquid file for the theme you want Rebuy to load on

  2. Paste the Rebuy JS script just above the closing </body> tag:

  3. Save the file

Rebuy JS Script:

<script async src="https://cdn.rebuyengine.com/onsite/js/rebuy.js?shop={{ shop.permanent_domain }}"></script>

Pro tip: Use Cmd+F (Mac) or Ctrl+F (Windows) to search for </body> in the file.

Rebuy will now only load on this specific theme.

Note: Product Page Widgets may need to be reinstalled on the new theme after completing this setup.


FAQs

Do customers need to be signed in for the customer tag method to work?

Yes, customers must be signed in for Rebuy to read their customer tags. If a customer is browsing as a guest, the conditional script won't be able to detect their tag and Rebuy will load by default.

I disabled the script tag in Rebuy Settings but Rebuy is still loading — what's wrong?

There are two common causes. First, check that the Rebuy Connector App Embed is also disabled. In Shopify Admin, go to your theme settings, open App Embeds, and toggle off the Rebuy Connector. Second, search your theme files for any additional instances of the Rebuy JS script — if it exists elsewhere in your theme, it will continue to load regardless of your Rebuy Admin settings.

Why isn't my conditional script working for wholesale or B2B customers?

The conditional script works by reading customer tags, which requires the customer to be signed into their account. If wholesale customers are browsing as guests, the tag check won't fire. Also confirm you've disabled App Blocks for that market in Shopify Admin, as App Blocks will load Rebuy even if your script tag is conditional. If your goal is to run Rebuy for your B2B customers rather than block it, see the guide on integrating Rebuy with your wholesale or B2B store.

Will this method work if I have the Rebuy JS script in multiple places in my theme?

No. If the Rebuy JS script exists in more than one place in your theme files, the conditional logic won't work — Rebuy will load from whichever instance isn't wrapped in the conditional. Search your theme for all instances of rebuy.js and ensure only the conditional snippet remains.

Did this answer your question?