How to add a "Send as a corporate gift" button to your Shopify store
The Corporate Gift Button adds a "Send as a corporate gift" button, or a link, to your Shopify product pages. When a shopper clicks it, your Trove storefront opens in a new tab with that product, and the variant they selected, already added to their gift order. Your own store stays open in the original tab.
You control how it looks. Use it as a styled button, or as a link inside your page copy.
Not on Shopify? See How to link to your products from your own website.
Before you start
- Your Shopify store is connected under Integrations in Trove, and your products are synced.
- Each product you want to gift is active and assigned to the Trove storefront you'll link to.
- You can edit your Shopify theme (Shopify admin → Online Store → Themes).
Step 1: Copy your script tag
- Log in to your Trove admin portal.
- In the left-hand navigation, open Integrations, then open your Shopify integration.
- Click the Corporate Gift Button tab. Under Store script tag, find the script tag for your storefront and click the copy icon. If you have more than one storefront, each has its own tag. Copy the one for the storefront you want gifts to go to.
It looks like this:
<script src="https://…/gift-button.js?storefront=your-storefront" defer></script>
If Store script tag shows "Set up a storefront to get your embed snippet", create a storefront first. If it shows "Gift button embed is not configured", contact support.
Step 2: Add the script to your theme (once)
- In Shopify, go to Online Store → Themes. Next to your live theme, click ⋯ → Edit code.
- Open
layout/theme.liquid. - Paste the script tag just before the closing
</body>tag. - Click Save.
You only do this once. It covers every product page.
Step 3: Add the button to your product page
Under Product page button on the same Trove page, you'll find two examples. Copy the one you want:
Button
<button data-trove-gift-button data-trove-product-id="{{ product.id }}" data-trove-variant-id="{{ product.selected_or_first_available_variant.id }}">Send as a corporate gift</button>
Link, for use within your page copy
<a data-trove-gift-button data-trove-product-id="{{ product.id }}" data-trove-variant-id="{{ product.selected_or_first_available_variant.id }}">Send as a corporate gift</a>
For example, a link inside a sentence on your product page:
Buying multiple gifts? Send to multiple addresses <a data-trove-gift-button data-trove-product-id="{{ product.id }}" data-trove-variant-id="{{ product.selected_or_first_available_variant.id }}">here</a>.
Then add it to your product template. Pick whichever route fits your theme.
Option A: Theme editor (no code, themes that support Custom Liquid blocks)
- Go to Online Store → Themes → Customize.
- Choose the Product template from the page selector at the top.
- In the product information section, click Add block → Custom Liquid.
- Paste the code and click Save.
Option B: Edit the theme code
- In Edit code, open your product section (commonly
sections/main-product.liquid, ortemplates/product.liquidon older themes). - Paste the code inside the product
<form>, near the Add to cart button. For a link in your product description, paste it into the text where you want it to appear. - Click Save.
Keep it inside the product form where possible. The widget reads the shopper's selected variant from that form. If your theme has no product form, it looks for a variant field anywhere on the page, then the ?variant= in the product page's address. Some themes only add that after the shopper picks a variant, so see Themes without a product form below.
Step 4: Test it
- Open a product page on your live store.
- Choose a variant, then click your button or link.
- Your Trove storefront should open in a new tab with that product in the cart, in the variant you chose. Your store should still be open in the original tab.
- Go back to your store, change the variant, and click again. The cart should match the new choice.
Customise the button or link
The button and link are plain HTML on your own page, so you can style them however you like. The widget adds no styles of its own.
Style a button to match your theme. Add your theme's button classes, or your own:
<button class="button button--secondary" data-trove-gift-button data-trove-product-id="{{ product.id }}" data-trove-variant-id="{{ product.selected_or_first_available_variant.id }}">Send as a corporate gift</button>
Use a link instead. Put the attributes on an <a> tag and style it with your theme's link classes or your own CSS:
<a class="link" data-trove-gift-button data-trove-product-id="{{ product.id }}" data-trove-variant-id="{{ product.selected_or_first_available_variant.id }}">Send as a corporate gift</a>
Change the wording. The text between the tags is yours to change. For example "here", "Gift this", or "Send to multiple addresses".
A few things to keep in mind:
- Keep the
data-trove-…attributes exactly as they are. They are what turn your button or link into a gift link. - Use a
<button>or an<a>tag. Other tags such as<div>or<span>work for mouse and touch clicks, but not for people using a keyboard. - Don't add your own
hrefortargetto a link. The widget sets the destination and opens it in a new tab for you. - The
{{ product.id }}value fills in automatically with each product's ID on your product page.{{ product.selected_or_first_available_variant.id }}also fills in automatically, with the ID of the variant that's selected or, failing that, the first available one. data-trove-variant-idis optional. Leave it off if your theme already works.
Themes without a product form
Some custom themes have no product form, and only add ?variant= to the address after a shopper picks a variant. To make sure a click before that still adds the right product, add data-trove-variant-id to your button or link:
<button data-trove-gift-button data-trove-product-id="{{ product.id }}" data-trove-variant-id="{{ product.selected_or_first_available_variant.id }}">Send as a corporate gift</button>
The widget works out the variant in this order when the shopper clicks:
- The variant field in the button's own product form
- Any variant field elsewhere on the page
- The
?variant=value in the page address - The
data-trove-variant-idattribute
The attribute is a starting default, and Shopify fills it in once, when the page loads. If your theme has neither a variant field nor ?variant= in the address, your theme's own code that runs when the shopper changes variant must also update the attribute, otherwise a shopper who switches variant gets the starting variant. The widget reads the attribute when the shopper clicks, so updating it is enough:
giftButton.setAttribute('data-trove-variant-id', variantId);
Troubleshooting
| Problem | What to check |
|---|---|
| Button or link does nothing | The script tag is saved in theme.liquid, the ?storefront= value matches your storefront, and the page was refreshed. |
| Storefront opens but the cart is empty | The product is active, assigned to that storefront, and synced to Trove. If your theme has no product form, add data-trove-variant-id as described in Themes without a product form. |
| Opens in the same tab instead of a new one | Your browser may be holding an older copy of the script. Refresh the page after a few minutes, or clear your browser cache. |
| Wrong variant added | The button or link is outside the product form and your theme has no variant field or ?variant= in the page address. Move it inside the form, or add data-trove-variant-id and make your theme update it when the variant changes (see Themes without a product form). |
| No Corporate Gift Button tab | The tab only appears on a Shopify integration. Open Integrations, then your Shopify integration. |
| No script tag under Store script tag | You'll see a message instead. Create a storefront if it asks you to, or contact support if it says the embed isn't configured. |