Hiding prices with manual code
Hiding prices and buy buttons by hand, for themes and situations the automatic settings can't reach
Most stores should use Locksmith's built-in price and buy-button hiding, which needs no theme code at all:
Hiding product prices and/or the add to cart buttonThis page covers the manual alternative. Reach for it when the automatic settings report Incompatible for your theme, when prices come from somewhere Locksmith's own integration can't see, or when you want to hand-place the message yourself.
The rest of this guide shows how to set up price hiding manually in your theme, using Locksmith's manual mode feature — an approach that can still be useful for special cases.
Enable manual mode
Before saving your lock, turn on "Enable manual mode" right there in the lock (Clicking "Advanced" will show the option):

Updating your theme for manual locking
You'll now need to let Locksmith know which parts of the page should be hidden. There are two methods to handling this:
Theme hiding profiles:
This method allows you define sections, blocks, or snippets which Locksmith will hide based on locks that have the Manual Locking option enabled.
This method shouldn't require any coding in your theme, if your theme is fully compatible. (Most modern themes are.) This is a newer feature, and we recommend trying this method first.
Here's a complete guide to setting this up:
Using manual locking code in your theme:
Because each theme is a bit different, adding manual locking code will require manually editing your theme to hide your pricing or add to cart buttons.
If you install a new theme down the road, these changes will need to be re-applied. Try the the Theme Hiding Profiles method first (outlined above), to avoid these limitations.
The rest of this guide gets a bit technical, we'll happily to the coding portion for you! If you've already created your lock (see step 1 of the main guide), simply write us a message at team@uselocksmith.com to request help.
If you are a developer type, and prefer to do the coding portion yourself, read on... You'll need to start by locating the places in your theme that show the price. Here are some examples of files that you might find the price in:
snippets/product-card-grid.liquid
templates/product.liquid
snippets/product-card-list.liquid
snippets/product-price.liquid
Each theme is very different, so those are simply examples. You'll need to go to each of the files that display price, and do the following steps:
Open up the Liquid file, and add this to the very top of the file:
Find the code you want to hide from unauthorized viewers, and wrap it with:
To hide prices, you'll be looking for elements like:
... or:
Example:

This shows Locksmith manual locking code wrapping an entire price section, which I've highlighted.
Save!
Remember, those 4 steps need to be done for each file that display the price.
Configuring Locksmith to hide the add-to-cart button only
You can still restrict purchasing products, while leaving the product details visible to the customer. This also a good option for those wanting to make sure that products are available for search engines to index.
As a reminder, we can help guide you through this process, including adding the code, so don't hesitate to get in touch.
Step 1 is exactly the same, but the code you add in step 2 will be slightly different.
Find the product-template or product-form file in your theme, and locate the code that generates the "add-to-cart" button. This is different for all themes, so it won't be possible to give you an exact location for this. Then, add the code that you want to render, inside of a Liquid "else" statement. For example:
This results in the add-to-cart button being replaced, in cases where the customer doesn't have access. What is shown depends on what is added above. Just make sure your key conditions on the lock match the conditions that you want your customers to meet before being able to purchase.
For stores using Shopify's legacy customer account system (formerly "Classic customer accounts"):
If you need to render a "Login to purchase" button, use the following code (the button classes may need to be edited). This button includes a redirect to return customers after login:
For stores using Shopify's customer account system (formerly "New customer accounts":
If you need to render a "Login to purchase" button, use the following code (the button classes may need to be edited). This button will return customers after login:
For locks using passcode keys:
If you need to render a passcode prompt button, use the following code (the button classes may need to be edited):
For locks using location keys:
You can add an access denied message of location keys by adding paragraph tags and some text within the Liquid "else" statement, for example:
When using the "is tagged with..." key condition you can display a "Login to purchase" button or an access denied message depending on a visitors access:
Here are some visual examples of the result
Requiring, a sign-in:

A passcode:

A country-specific visitor:

Last updated
Was this helpful?
