Remove Blocks Based on Country
In this tutorial, we’ll guide you through removing a block from the product, cart, drawer, and multiship views based on the customer’s country.
Important Note: This is an advanced tutorial designed for qualified Shopify developers with JavaScript experience. If you’re not working with a developer and need assistance, we can implement this for a flat fee of $100 USD. Payment can be made at: https://shop.gist-apps.com.
Step 1: Duplicate Your Live Theme
Always work on a duplicated development theme to ensure your live store remains unaffected by changes.
Step 2: Create and Upload the Snippet
- Navigate to the Assets folder of your theme.
- Create a new JavaScript file named giftship-country.js.
- Copy and paste the following code into the file:
(() => { const MODULE = { Country: "US", // CA inputName: "date", init: function () { this.registerEventHandlers(); }, getUser: function () { return { customerCountry: Shopify.country, currentPage: window.GSSDK.page.get(), }; }, registerEventHandlers: function () { document.addEventListener('giftship.loaded', this.handleGiftshipLoaded.bind(this)); document.addEventListener('giftship.shipping.ready', this.handleShippingLoaded.bind(this)); document.addEventListener('giftship.drawer-cart.opened', this.handleDrawerOpened.bind(this)); }, handleGiftshipLoaded: function () { const { customerCountry, currentPage } = this.getUser(); if (customerCountry === this.Country) { if (currentPage === "product") { this.removeDivs(`[data-child-name="${this.inputName}"]`, '#gsAppContainer'); } else if (currentPage === "cart") { this.removeDivs(`[data-child-name="${this.inputName}"]`, '#gsAppContainer'); } } }, handleShippingLoaded: function () { const { customerCountry, currentPage } = this.getUser(); if (customerCountry === this.Country && currentPage === "multi-shipping") { this.removeDivs(`[data-child-name="${this.inputName}"]`, '#gsMultishippingPage'); } }, handleDrawerOpened: function () { const { customerCountry } = this.getUser(); if (customerCountry === this.Country) { this.removeDivs(`[data-child-name="${this.inputName}"]`, '#gsDrawer'); } }, removeDivs: function (selector, containerId) { const container = document.querySelector(containerId); if (!container) return; const divs = container.querySelectorAll(selector); if (divs.length === 0) { const observer = new MutationObserver((mutations, obs) => { const newDivs = container.querySelectorAll(selector); if (newDivs.length > 0) { newDivs.forEach(div => div.remove()); obs.disconnect(); } }); observer.observe(container, { childList: true, subtree: true }); } else { divs.forEach(div => div.remove()); } }, }; MODULE.init(); })();
Step 3: Replace the Block Name & Country Code
Replace the block name (e.g., “Date”) with the desired block you want to modify, and replace the country (e.g., “US”) with the desired country you want the block removed for.
Step 4: Edit theme.liquid
to Include the Snippet
- Open
theme.liquid
in your theme editor. - Scroll to the bottom of the file, just above the closing
</body>
tag. - Paste the following code:
<!-- Include your new JavaScript file here --> <script src="{{ 'giftship-country.js' | asset_url }}"></script>
Step 5: Test
Open your browser’s console and type “Shopify” to expose the Shopify global object. You will see the country code you are currently viewing. You can switch country codes by visiting: Giftship > Settings > Markets and previewing the corresponding market.
Can't find the answer in our documentation?
Contact Support Drawer Cart: Automatically Clear Datepicker After X Hours
Automatically Add Upsell (e.g. Insurance) in Drawer Cart
Disable Multiship Call to Action in Drawer Cart for Certain Product Types
How to Add Product Bundles Manually to Cart
Google Font Real-Time Personalizer
Remove Blocks Based on Country
Remove British Forces from Multi-Address Modal
Preset Bundles: Automatically Ensure All Products in an Upsell Block Are Added to Cart
How to Add Custom Scripts to Multiship
Conditionally Showing Datepicker Blocks Based on Product Types in Cart Using the Hidden Input Block
Showing Product Option Blocks Based on Customer Tags with the Hidden Input Block
Event API Example: Automatically Add an Ice Pack to Each Shipment in the Multiple shipping Address Process
Drawer Cart CSS Styling Options
Preventing Checkout Until Giftship Bundles are Loaded
Javascript Event API
Showing Product Option Blocks Based on Product Variants with the Hidden Input Block
Edit Gift Messages etc on Multiship and Cart Page in Giftship
Adding Bundles when a User Navigates to the Cart Page
How to show bundle price on product page as bundle is built
Conditionally Hide Giftship Options Based on Your Carts Contents
Giftship Checkout API ⚒️