Do you need to prevent specific customers from checking out on your website? It is a step down from the nuclear option of disabling your store.
Publish Insights 14 August 2021
Sometimes You Need To Pull The Plug
We love all our customers. But sometimes there is a need to freeze an account until problems resolve. It may be your fault or theirs. Either way, before accepting new orders, you want to prevent checkouts. Potential problems include:
- Awaiting product return
- Invalid shipping destination
- Uncooperative customer
- Outstanding balance
You can disable the add-to-cart and checkout buttons when a customer account includes a hidden tag. This prevents you from shutting down your entire website.
You need to enable the global Shopify option in your settings under Checkout that requires login to checkout. When this is done, customers can add products to a shopping cart. When they press the checkout button, they are prompted to login.
With the code injection, you can override a site banner message and disable shopping buttons. Your site needs to read the customer tag. So this method only works when customers login before shopping. Cart recovery invoices can bypass the account freeze. You will need to manually cancel orders that come in from suspended customers that bypass your cart modification. In addition to the customer tag, you can manually add an internal customer note that displays on orders that alerts you with “Account suspended.”
Since each Shopify theme is different, you need to determine where and which templates you require suppressed code. Hiring a Shopify Partner may be necessary. If you can live with these limitations, continue reading.
Roll Up Your Sleeves
Before making modifications to your Shopify theme, it is good practice to duplicate it. Within Admin, under the lefthand navigation, choose Online Store: Themes: Actions: Duplicate.
Caution: Modifying Liquid code may invalidate your theme for future updates by the developer. Anything you add will require manual migration to a different theme, with possible incompatibility.
Now you access the Liquid programming code with Actions: Edit code menu. Locate the file under Config called settings_schema.json. Logical places to add the code below are within either the Cart or Checkout section. You should see something like this:
"name": "Cart",
"settings": [
Insert the following code within the json file:
{ "type": "header",
"content": "Account suspension notice"
},
{
"type": "text",
"id": "suspend_account",
"label": "Customer account suspension tag",
"info": "Disable shopping for customers with this tag.",
"default": "blocked"
},
{
"type": "text",
"id": "suspend_account_message",
"label": "Customer account suspension banner message",
"info": "Display banner notifying blocked account after login.",
"default": "Account suspended – Request details with contact form"
}
Feel free to edit the default text (blocked and banner message). This adds options to the theme’s Customize Theme settings that look similar to the image below. There, you can change the keyword tag and banner message.
Create a (true/false) flag based on the global settings above within your cart template. Use this named flag to disable buttons or display a banner message.
{% comment %} // customer exclusion // {% endcomment %}
{%- if customer and customer.tags contains settings.suspend_account -%}
{%- assign blocked = true -%}
{%- endif -%}
You may need to edit at least three templates: Announcements, Cart, and Product. The actual names vary for each Shopify theme. Within these templates you will insert one the following three lines of code, based on your theme:
{%- unless blocked -%}
existing code{%- endunless -%}
{%- if blocked -%}{{ settings.suspend_account_message }}{%- else -%}
existing banner message{%- endif -%}
{%- if blocked -%}
alternate button code{%- else -%}
To enable the feature, tag appropriate customers. With filters, you can add a tag to one customer, a group within a country, or customers matching other criteria. As a courtesy, it may be advantageous to notify the customer(s) that the account is suspended.
Your alternate button code on product pages can take the visitor to the home page, customer account page, or a special page that explains reasons for account suspension and how to reactivate it.
There is no need to modify code in order to exclude a country. Within Admin, click Settings: Shipping and delivery. There you should have shipping rates for your country and the rest of the world. Edit the rest of the world by deselecting countries. Visitors from those regions will not be able to checkout.
The option to block customers is currently enabled on the ClinicalPosters website. As a Shopify Partner, we can add this option to your store. Are you interested in more tips and code snippets like this? Please indicate so within the comment field.
Main image by Christina Morillo from Pexels.