Hide Empty Cart

Hide Empty Cart

I was looking for a way to hide the shopping cart icon when the cart is empty. I couldn't find my answer online and reached out to support. They offered the following code, which works great.

I wanted to add it here, in case it may help someone else. The following code needs to be added to Site Settings > Header and Footer Code > Header Code.

  1. <script>
  2.     document.addEventListener("zp-event-cart-count", isCartEmpty);
  3.     function isCartEmpty(cartCountEvent){
  4.         let cartCount = document.querySelector("[data-zs-view-cart-count]");
  5.         let cartIcon = document.querySelector("[data-zs-view-cart]");
  6.         if((cartCountEvent.detail.cart_count === 0)){
  7.             cartCount.style.display = "none";
  8.             cartIcon.style.display = "none";
  9.         } else {
  10.             cartCount.style.display = "block";
  11.             cartIcon.style.display = "block";
  12.         }
  13.     }
  14. </script>

      Zoho Campaigns Resources


        • Desk Community Learning Series


        • Digest


        • Functions


        • Meetups


        • Kbase


        • Resources


        • Glossary


        • Desk Marketplace


        • MVP Corner


        • Word of the Day


        • Ask the Experts


          Zoho CRM Plus Resources

            Zoho Books Resources


              Zoho Subscriptions Resources

                Zoho Projects Resources


                  Zoho Sprints Resources


                    Zoho Orchestly Resources


                      Zoho Creator Resources


                        Zoho WorkDrive Resources



                          Zoho CRM Resources

                          • CRM Community Learning Series

                            CRM Community Learning Series


                          • Tips

                            Tips

                          • Functions

                            Functions

                          • Meetups

                            Meetups

                          • Kbase

                            Kbase

                          • Resources

                            Resources

                          • Digest

                            Digest

                          • CRM Marketplace

                            CRM Marketplace

                          • MVP Corner

                            MVP Corner




                            Zoho Writer Writer

                            Get Started. Write Away!

                            Writer is a powerful online word processor, designed for collaborative work.

                              Zoho CRM コンテンツ



                                ご検討中の方