Hide cart icon unless logged in

Hide cart icon unless logged in

Solly
Visitor
2 0 1

I'm wondering what code is needed to hide cart icon before customer is logged in?

I'm using Trade theme.

It's a B2B site.

Thanks in advance!

Replies 2 (2)

BSS-TekLabs
Shopify Partner
2401 695 832

- Here is the solution for you @Solly 
- Please follow these steps:

step.png

- Then find the theme.liquid file.
- Then add the following code at the end of the file and press 'Save' to save it.

-  Paste the below code before </body> on theme.liquid

{% unless customer %}
<style>
.product-form__buttons {
display: none !important;
}
</style>
{% endunless %}

- If it doesn't work, please share your store link for me to check

 

- Please press 'Like' and mark it as 'Solution' if you find it helpful. Thank you.

If our suggestions are useful, please let us know by giving it a like or marking it as a solution.


Salepify: Efficiently increase sales conversion with sale-driven features like auto add to cart, free gifts (free plan available)


Salemate: Boost your AVO with 2-layer offer, countdown upsell in your post purchase page


BSS Commerce - Full-service eCommerce Agency | Use Shopify for 1$ in the first month now

Dan-From-Ryviu
Shopify Partner
11633 2280 2462

Hi @Solly 

You can do that by following these steps

  • Please log in to your Shopify store admin
  • From Sale channels > Online Store
  • In Themes > click "..." next to Trade theme > Edit code
  • Open header.liquid file
  • Replace code from lines 289 to 306 with this code below and save file

 

{% if customer %}      
    <a href="{{ routes.cart_url }}" class="header__icon header__icon--cart link focus-inset" id="cart-icon-bubble">
        {%- liquid
          if cart == empty
            render 'icon-cart-empty'
          else
            render 'icon-cart'
          endif
        -%}
        <span class="visually-hidden">{{ 'templates.cart.cart' | t }}</span>
        {%- if cart != empty -%}
          <div class="cart-count-bubble">
            {%- if cart.item_count < 100 -%}
              <span aria-hidden="true">{{ cart.item_count }}</span>
            {%- endif -%}
            <span class="visually-hidden">{{ 'sections.header.cart_count' | t: count: cart.item_count }}</span>
          </div>
        {%- endif -%}
  </a>
{% endif %}​

Screenshot_2.jpg

 

 

- Helpful? Like & Accept solution!
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- En...
Sign up now.