Jump to content

[Share] Summary Block Add to Cart

Recommended Posts

Posted

Description

  • Adding add to cart button to Summary Block
  • Click Add to cart >> add product to Cart
  • This works with Summary Block List/Grid design only

If code doesn't work, you can share link to page where you use Summary Block, I will check again.

#1. Suppose we have a Summary Block with these Products. We will find the way to add “Add to Cart” button here.

image.png.6d108b2eb0155fe847dc3b44dc20ac76.png

#2. First, edit each product > Additional Info > Add text "Add to Cart"

image.png.403e8e95cd9388d70855c5ca0fde9c33.png

Highlight it > Enter this URL:

#product100

(each product, you will enter a different number, you can use any numbers what you want, but read carefully below steps to make sure number here and number in next steps are consistent).

Make sure "Open in New Tab" is disabled.

image.png.7e64cd8c2db4af155ea85897b3fc2e93.png

image.png.500ce49c82725f14f0f78d81321676df.png

We will have

image.png.67115048c578f02235444a7096d274bc.png

#3.1. Next, add a Section under Summary Block > Then add 3 Product Blocks

image.png.ae1b19b57dd801dacfe8edf2bc8d74bf.png

image.png.bf2b5c63d73b25883ad1769856e24981.png

Make sure you enabled "Add to Cart button"

image.thumb.png.e245f810c543a6fdb6237aac0d70d047.png

We will have

image.png.b2ad3d8f0fad5b15981331c2d5549619.png

#3.2. Next, find ID of this Section

 

In my example, we will have:

section[data-section-id="671ec9546d81bb36bbe7db2d"]

image.png.413d39cf6b0f1f8ce1429f43f1a6c597.png

Next, use this code to Custom CSS box. Code will hide this Section from Preview/Live Mode, and show it in Edit Mode only.

body:not(.sqs-edit-mode-active) section[data-section-id="671ec9546d81bb36bbe7db2d"] {
  display:none;
}

image.png.86b2c9a6cbc167fc77fb8a1226820e47.png

#4. Find ID of 3 Product Blocks. Use tool in #3.2.

In my example, we will have:

  • 100. One-hundred: #block-yui_3_17_2_1_1730070417388_21392 99
  • Ninety-nine: #block-yui_3_17_2_1_1730070417388_22146 98
  • Ninety-eight: #block-01208d116f9191496bd8

image.png.533663ff53e9b7bc7d82ad893113bba4.png

#5. Use this code to Code Injection Footer (or Page Header Injection, Page where you use Summary Block).

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
  const products = {
    "product100": "block-yui_3_17_2_1_1730070417388_21392",
    "product99": "block-yui_3_17_2_1_1730070417388_22146",
    "product98": "block-01208d116f9191496bd8"
  };
  $.each(products, function(productID, blockID) {
    $(`a[href="#${productID}"]`).on("click", function(event){
      event.preventDefault();
      $(`#${blockID} .sqs-add-to-cart-button`)[0].click();
    });
  });
});
</script>

image.png.48b699556f8a3fa32b08102fa2f2ea2f.png

When users click Add to Cart in Summary Block >> It will click Add to Cart in hidden Section Product Block.

image.png.dc6298d0a1455c1affc79d0aa706e59f.png

You need to change these values in the code

image.png.a2dd2b917210d57d84d951293a237c11.png

#6. To style "Add to Cart" link, you can use this code to Custom CSS box

div.summary-item [href*="#product"] {
    background-color: #000;
    color: #fff;
    padding: 5px 10px;
    border-radius: 50px;
    transition: all 0.3s ease;
}
div.summary-item [href*="#product"]:hover {
    opacity: 0.7;
    transition: all 0.3s;
}

image.png.f0a4bb0162f3d089f82e005cc9a2452b.png

Result

image.png.708dbec2f506c3049d82dd6303779008.png

#7. If you want to remove Excerpt under Price, you can use this CSS code

div.summary-item:has([href*="#product"]) p {
    display: none;
}
div.summary-item:has([href*="#product"]) p:has([href*="#product"]) {
    display: inline-block;
}

image.png.6dd120bb86eef9cc486b3f517acdedc4.png

Result

image.png.fb271861c36575eb6fd96b88358b58f4.png

#8. If you want to remove Add to cart link in Product Description

image.png.dbd67f8342229c3aa3308668e1e24395.png

You can use this code to Custom CSS box

body.view-item .product-details p:has([href*="#product"]) {
    display: none;
}

image.png.17f5834fa41405f8af063bcb20c32dc2.png

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

  • Replies 0
  • Views 265
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted Images

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.