What's your biggest current challenge? Have your say in Community Polls along the right column.

Re: How to auto open product description as default in accordion tab

Solved

How to auto open product description as default in accordion tab

surfingcinv
Excursionist
41 1 14

Hello,

 

I found this article and followed the code, but its not working on my store. What am I doing wrong?

https://community.shopify.com/c/shopify-discussions/set-bar-as-open-in-product-description/m-p/19063...

 

<script>
$(document).ready(function(){
$('.product__accordion').each(function(el,item){
if (el === 0){
$(this).find('details').attr('open', '');
$(this).find('summary').attr('aria-expanded','true');
}
})
})
</script>

 

This is the store URL

https://www.iamgreenminded.com/products/bakuchiol-serum-retinol-alternative-phyto-r5

 

1_2024-06-09 17_21_07-Window.png2_2024-06-09 17_21_07-Window.png

 

 

Accepted Solution (1)

surfingcinv
Excursionist
41 1 14

This is an accepted solution.

Solution was adding  " open" to the code in the following screenshot 1_2024-06-09 17_21_07-Window.png

View solution in original post

Replies 18 (18)

Dan-From-Ryviu
Shopify Partner
10296 2044 2115

Hi @surfingcinv 

You can try changing the code to this, but I guess it will open all tabs by default. 

<script>
document.addEventListener("DOMContentLoaded", function() {
    var accordions = document.querySelectorAll('.product__accordion');
    accordions.forEach(function(item, index) {
        if (index === 0) {
            var details = item.querySelector('details');
            var summary = item.querySelector('summary');
            if (details) {
                details.setAttribute('open', '');
            }
            if (summary) {
                summary.setAttribute('aria-expanded', 'true');
            }
        }
    });
});
</script>

 

- Helpful? Like and Accept solution! Or Support me: Buy Coffees
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.

surfingcinv
Excursionist
41 1 14

Thanks. But I need only the product description section auto opened

surfingcinv
Excursionist
41 1 14

This is an accepted solution.

Solution was adding  " open" to the code in the following screenshot 1_2024-06-09 17_21_07-Window.png

PaulMartin
Shopify Partner
618 59 146

Hey @surfingcinv

I am assuming you are using Dawn, based on your previous post. This comment will be a step-by-step guide in order to attain what you are looking for.

To start, go to your code editor. Head to Online Store > Themes > ... of the theme you want to edit > Edit code. 

PaulMartin_0-1717996833639.png

Then search for the file named "main-product.liquid", ensure that you are in the Sections folder. Open that file

PaulMartin_1-1717996963035.png

Then by using CTRL + F, look for this piece of code. It should be at the 900th line or somewhere close to that

"type": "collapsible_tab"

PaulMartin_2-1717997237187.png

Next, I want you to add this piece of code here, just like the image after the code below. Then save the file.

{
"type": "checkbox",
"id": "custom_open_default",
"label": "Open by default",
"default": false
},

PaulMartin_3-1717997395663.png

Now the setup is done. Next, we'll be adding more code in order to make that added setting work as it should.

In the same file, CTRL + F, and find this piece of code. It should be at the some 200s line.

when 'collapsible_tab'

PaulMartin_4-1717997569763.png

Next, I want you to add this piece of code here, just like the image below this code:

{% if block.settings.custom_open_default %} open {% endif %}

PaulMartin_5-1717997752798.png

Then click save. That should be all the code additions needed.

Now head to your theme editor and click on the description block. And you should see the new setting we added for the setup. If you mark it checked and save your theme, that collapsible row will be opened by default.

PaulMartin_6-1717997996809.png


Here's a demo of that working flawlessly. 
Product A – martin-dumpstore
Password: 1

If you got any questions, let me know. And if there are any unclear instructions, let me know and I will guide you in order to make this possible on your store.

contact@paulmartinlopez.com
Feel free to email me! 😄
I'm open to conversations or work ʕ •ᴥ•ʔ
PaulMartin
Shopify Partner
618 59 146

Oof, I thought it was the collapsible tab. Guess it was just the product description, my bad there. Good work on getting it sorted out @surfingcinv !

contact@paulmartinlopez.com
Feel free to email me! 😄
I'm open to conversations or work ʕ •ᴥ•ʔ
deep_wrinkle
Visitor
1 0 0

Hi there, I am also looking to have the first accordion tab open by default on all my product pages. I am currently using Sahara as my theme. 

PaulMartin
Shopify Partner
618 59 146

Hey Deep,

Since Sahara is a paid theme, I don't know the code inside of it, so I can't give you instructions to follow. Sorry Deep.

 

If, however, you're open to the idea of giving me access via collab (Shopify Help Center | Collaborator accounts), I can very certainly take care of it for you. I usually do this as a paid service but, for this time, I can do it for free. Just let me know via my email below and I'll get back to you within 24 hours.

contact@paulmartinlopez.com
Feel free to email me! 😄
I'm open to conversations or work ʕ •ᴥ•ʔ
HansØstergaard
New Member
6 0 0

Hello Paul.

 

I am trying to do the thing you are explaining, also in the theme dawn. But in step where i need to find this line of code: "type": "collapsible_tab", it isn't possible? Do you know why? You can see what i have done in the screenshot.

Skærmbillede 2024-11-27 kl. 19.56.40.png

 

Hope you can help

 

Bets Regards

Hans Ø

PaulMartin
Shopify Partner
618 59 146

Hey Hans,

 

It looks like you have a different theme other than Dawn? Can you check, like the screenshot below?

PaulMartin_0-1732759028738.png

contact@paulmartinlopez.com
Feel free to email me! 😄
I'm open to conversations or work ʕ •ᴥ•ʔ
HansØstergaard
New Member
6 0 0

Hey Paul

Thats right😅 I have the nitro theme. Is it possible to do the same thing, in that theme?

Skærmbillede 2024-11-28 kl. 08.49.47.png

 

Best Regards

Hans Ø

Dan-From-Ryviu
Shopify Partner
10296 2044 2115

Can you share your store link so we can check? 

- Helpful? Like and Accept solution! Or Support me: Buy Coffees
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.

HansØstergaard
New Member
6 0 0

Of course: https://plaineyewear.dk/ 

 

PaulMartin
Shopify Partner
618 59 146

Hi @HansØstergaard,

 

Was Dan able to help you with this?

contact@paulmartinlopez.com
Feel free to email me! 😄
I'm open to conversations or work ʕ •ᴥ•ʔ
HansØstergaard
New Member
6 0 0

Hi again!

I have unfortunately not received an answer yet. So at this point i haven't got the help i need.

PaulMartin
Shopify Partner
618 59 146

I see, hmm, I was assuming they were going to help that's why I didn't reply after a few days.

 

I'll handle the problem for you.

 

Could you send me an email through my contact email below? I wish I could give you instructions, but I can only do so if you're using Dawn. So, we'll need to move to a private conversation because I'll need to request access to your theme in order to make the changes.

 

Then, let me know once you've sent an email because sometimes my contact email bugs, and I won't receive any incoming email. 

 

Thanks Hans

contact@paulmartinlopez.com
Feel free to email me! 😄
I'm open to conversations or work ʕ •ᴥ•ʔ
HansØstergaard
New Member
6 0 0

Just send a message

 

PaulMartin
Shopify Partner
618 59 146

Thank you, Hans! Just replied to your email, check it out if you haven't yet.

contact@paulmartinlopez.com
Feel free to email me! 😄
I'm open to conversations or work ʕ •ᴥ•ʔ
HansØstergaard
New Member
6 0 0

Thanks. I have received it