> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://support.teeinblue.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Cross-Sell: Redirecting Product A to Product B

In this guide, we will walk you through setting up a feature that automatically redirects customers to Product B after they add Product A to their cart (ATC), using metafields.

![](https://storage.crisp.chat/users/helpdesk/website/-/6/0/8/5/6085dc2a7293d800/crosssellproductgif-optimize_oqzzvs.gif)

|| The redirect function will not work if the product has already been added to the cart.

# Instructions

###### Step 1: Set Up a Metafield for Redirect Target
* In your **Shopify Admin**, go to **Settings** > **Metafields and metaobjects** > **Products**.

![](https://storage.crisp.chat/users/helpdesk/website/-/6/0/8/5/6085dc2a7293d800/image_15pgvz6.png)

* Click the **Add definition** button.

![](https://storage.crisp.chat/users/helpdesk/website/-/6/0/8/5/6085dc2a7293d800/image_14hrs2u.png)

* Under the `Name` field, enter `Cross Sell Product` and set the field type to **Product.** Please ensure to click **Save** afterward.

![](https://storage.crisp.chat/users/helpdesk/website/-/6/0/8/5/6085dc2a7293d800/image_u2dirt.png)
* Return to the **Products** section, find the product you’d like to set up, and scroll down until you see the **Product metafields** section.

![](https://storage.crisp.chat/users/helpdesk/website/-/6/0/8/5/6085dc2a7293d800/image_6z1cx7.png)
* Set this field’s value to the product you want customers to be redirected to after the original product is successfully added to the cart.

###### Step 2: Implement Liquid Code in Your Theme
* Navigate to **Online Store > Themes** and select **Edit Code**.

![](https://storage.crisp.chat/users/helpdesk/website/-/6/0/8/5/6085dc2a7293d800/image_5nptg4.png)

* Locate and open the `theme.liquid` file. Find the `</head>` tag and insert the following code **right before** it.

```javascript
<script type="text/javascript">
      teeinblue = {
        ...(window.teeinblue || {}),
        onItemAdded: function(item) {
          {% if product.metafields.custom.cross_sell_product.value %}
            const crossSellHandle = "{{ product.metafields.custom.cross_sell_product.value.handle }}";
            const crossSellUrl = "{{ product.metafields.custom.cross_sell_product.value.url }}";
            fetch('/cart.js')
            .then(res => res.json())
            .then(cart => {
              const isProductInCart = cart.items.some(item => item.handle === crossSellHandle);
              if (!isProductInCart) {
                window.location.href = crossSellUrl;
              } else {
                console.log("The cross-sell product is already in the cart.")
              }
            });
          {% endif %}
        }
      }
</script>
```

![](https://storage.crisp.chat/users/helpdesk/website/-/6/0/8/5/6085dc2a7293d800/image_w2xrkh.png)

###### Step 3: Check your storefront
* Click **Save** to apply the changes. Then, return to your storefront and test the ATC process to make sure the redirect works as expected.

| Things change all the time so if you run into any issues or need our help, please don't hesitate to reach out to us via Live Chat or email. We're happy to lend a hand 🤩