Jump to content

[Share] Assign Accordion based on Product Category

Recommended Posts

If you can't make code work, you can share link to site url & let me know which tags you create, I can check your case easier.

Suppose you have 6 products: A, B, C, D, E, F, and 3 product categories: Bike, Car, Plane.

You want products in each category to use the same accordion block (accordion will be under Add to Cart).

Instead of manually adding accordion block into Additional Info, you want to add it automatically to products in these 3 categories, each with a different accordion.

#1. You create 3 tags: Bike, Car, and Plane, and assign them to corresponding products.

image.png.62a3ee6e1f3e3e1f668466a2af172923.png

image.png.58e50fff6b1ba774463223ed5412bc1e.png

image.png.21ddd417b0a8ed9b582812ca4dff3fad.png

#2. Create a Section in Footer and add 3 Accordion Blocks

image.thumb.png.63ac531f3d5b90d8d69a9b2bb9f85e92.png

#3. Use below tool to find ID of Section and ID of 3 Accordion Blocks

In my example, we will have: 

  • Section ID: section[data-section-id="66b2f38aeba08e7a2aca632a"]
  • Bike Accordion: #block-yui_3_17_2_1_1723456323817_6082
  • Car Accordion: #block-6a756d4bb38faeb1c5ff
  • Plane Accordion: #block-a599ce29b69a05524dcd

image.thumb.png.3bf025c230edf60c7fc54347a5ad0ea2.png

#4. Use this code to Code Injection > Footer

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
jQuery(document).ready(function($){
    // bike
  $('#block-yui_3_17_2_1_1723456323817_6082').insertAfter('.ProductItem.tag-bike .sqs-add-to-cart-button-wrapper');
    // car
   $('#block-6a756d4bb38faeb1c5ff').insertAfter('.ProductItem.tag-car .sqs-add-to-cart-button-wrapper'); 
    // plane
    $('#block-a599ce29b69a05524dcd').insertAfter('.ProductItem.tag-plane .sqs-add-to-cart-button-wrapper');  
})
</script>

image.thumb.png.36e54d4947c3f8d376046a8b52831a8c.png

#5. Use this code to Custom CSS box

section[data-section-id="66b2f38aeba08e7a2aca632a"] {
	display: none !important;
}

#6. Result

image.png.eb6214f4d0da6396a9c9dbc9734b3eb1.png

image.png.d5fba5822694f1903c8d02c72dbaf371.png

image.png.056c03281c68bc41ccb1176611d0e55d.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!)

Link to comment
  • Replies 0
  • Views 693
  • 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.