Hiding the Add to Cart Button

If you have created a membership rule to only show the "Add to Cart" button to members, this will walk you through updating your theme

Alfonso avatar
Written by Alfonso
Updated over a week ago
We don't want you to edit your theme code if you don't want to! We encourage you to ask for setup assistance by clicking on the chat button and asking us to update your theme.

So, you decided that you only want members to be able to add products to their cart - that's a bold move! Not a problem, we're here to help. This update is not done automatically to your theme since themes can do this in so many ways.

Create the Rule

If you haven't done this already, open Simplee Memberships, go to Plans, then create or edit the plan you want this to apply to.

In the Rules section, click to add a new rule, select Show add to cart button only to members, then save the plan.

Edit Your Theme

Now, we need to find where in the code your add to cart buttons are located. We'll focus on the one that almost every store has - the product page.

In your Shopify admin, click on Online Store, find the theme you want to edit, then click Actions > Edit Code

Next, follow these steps:

  • In the Templates folder, click on product.liquid

  • This template will often point to a section or other file which loads the body of the product page. In many cases it will be product-template - when you hover over this name, you can click the arrow to open the file

  • In product-template.liquid, we want to find the section which contains the button to submit the product to the cart. Search (Ctrl or Cmd-F) for "submit" and look for the <button> which mentions adding to cart

  • This button will be surrounded by an opening <div> and closing </div>. To disable this button, we'll add a bit of code before and after the div tags.

Before, add this code:

{% liquid  
assign sm_rules = shop.metafields.simplee.memberships.rules
assign sm_show_cart = true
assign sm_config = shop.metafields.simplee.memberships.config

if customer
for tag in customer.tags
if sm_config["active_tags"] contains tag
assign sm_active_tag = tag

for rule in sm_rules
if rule["type"] == "cart"
assign sm_show_cart = false
assign all_tags = rule["tags"] | split:','
if all_tags contains sm_active_tag
assign sm_show_cart = true
{% if sm_show_cart or sm_config["active_products"] contains product.id %}

After the closing </div>, add this code:

 {% endif %}

Save your theme, then visit a product page to see if the Add to Cart button appears when you are not logged in as a member.

If that worked, login as a member, and see if the button appears. We hope that worked! 🀞

For help with this, please chat with our team now - we want to help!

Did this answer your question?