Skip to content
Advertisement

Woocommerce short description toggle on archive page

Im building shop on woocommerce and im trying to make spoiler under product with short description on archive page. But unfortunetely it works only with first product. I made changes inside content-product.php

JavaScript

Here is a css:

JavaScript

And Jquery

JavaScript

I think problem is with Jquery. I dont know it very well. I put script and css to to header with Insert Headers and Footers plugin it works like below on the screenshot. Thanks in advance!

How it looks right now

Advertisement

Answer

IDs are unique identifiers and should only be existing once on a page.

Your jQuery script is getting the id “tog” and uses the click function. You are only do this for the first element with this id.

You should use a class instead and could use a for each to add this click function to all elements with this class.

Another method would be to add the on click to the html tag

JavaScript

and create a function where you are referencing to “this” to always use THIS element which is clicked.

EDIT: Here is an example code for you, to make things clearer

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement