How to Restrict Shipping by Customer Tag on Shopify

Overview

This document outlines the process to show certain shipping rates to specific customer groups such as a Wholesale Customer Tag while hiding them from others such as your Retail Customer Tag on your Shopify store using a VIP shipping customer tag.

The information and example provided below are intended to help point you in the right direction. ShipperHQ does not provide Shopify Scripting development services. For detailed information on how to use Shopify Scripts, see Shopify’s documentation on using Shopify Scripts and the Script Editor App and the Shopify Scripts API Reference.

Requirements

Before you begin, please ensure you have the following:

  • ShipperHQ installed on your Shopify Plus store
  • Access to the Shopify Script Editor
  • Shipping rates configured in ShipperHQ for your standard and VIP customers
  • The Script Editor app installed from the Shopify App Store

ShipperHQ Setup

For this example, ShipperHQ has a table rate carrier setup with two shipping methods: Standard (method code is delivery) and VIP (method code is delivery_vip). We also have a customer tag in Shopify of VIP.

How to Create Script in Shopify Script Editor

    1. Log into your Shopify Plus admin store.
    2. Navigate to the Apps > Script Editor dashboard.
    3. Click the Create Script button.
    4. Select any script category.
    5. Click Create Script from the modal dialog.
    6. Change the Title of your script.
    7. Leave the Channels set to Online Store and Storefront API channels
    8. Click the Code tab.
    9. Paste the following script inside Ruby source code:
VIP_CUSTOMER_TAG = 'VIP'
VIP_SHIPPING_METHOD = "delivery_vip"

if !Input.cart.customer.nil? and Input.cart.customer.tags.include?(VIP_CUSTOMER_TAG)

    Output.shipping_rates = Input.shipping_rates.delete_if do |shipping_rate|
        !shipping_rate.code.end_with?(VIP_SHIPPING_METHOD)
    end
else
    Output.shipping_rates = Input.shipping_rates.delete_if do |shipping_rate|
        shipping_rate.code.end_with?(VIP_SHIPPING_METHOD)
   end
end
  1. Click the Save and publish button.
  2. Tag a customer with the VIP tag.
  3. Go to your Shopify Plus storefront.

Results

With the setup described above, what’s happening is that ShipperHQ is returning two shipping options but the script is being used to hide one or the other option based on the customer’s Customer Tag. If the customer has a Customer Tag of “VIP”, the script hides all shipping methods other than “VIP” and if the customer has a Customer Tag other than “VIP, the script hides the “VIP” shipping method.

Now the VIP shipping method is only visible to the customer tagged with the VIP tag:

Other customers will only see the “Delivery” method:

Troubleshooting

Fo debugging, you can use Input tab to modify input parameters.  In the script, you can use puts to dump objects to the Console (located below Ruby source code field). Then click Run script in the Output panel to see the results.

Was this doc helpful?