How to Restrict Shipping for Customer Groups on Shopify

Overview

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

Requirements

Before you begin, please ensure you have the following:

  • 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 group 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.
  4. Now the VIP shipping method is only visible to the customer tagged with the VIP tag:

Note, other customers only view  “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?