I am hoping someone can please help me out here. I've been struggling for 3 days. :)
I am new to wordpress-woocommerce & php, but the theme I am using does not show any "signs" when an item is added to cart with Ajax cart. I am not good with programming, but created some Javascript to try and conquer this issue. Unfortunately, right now if you click one button, ALL buttons change.
I would like the code to only apply to the button actively being clicked.
The main criteria:
- The buttons cannot have separate ids. Must use class alone
- Buttons are dynamically generated for each product, and the number of products-per-page is unpredictable
- Something like, "onclick="this.innerHTML='hi Stack!'" cannot be used I think (it breaks the category page)
This is the pen of what I have so far including the html, css, and js: http://codepen.io/xkurohatox/pen/eNbMKb
HTML
<a href="#" class="button add_to_cart_button product_type_simple added" onclick="birds()">Add to Cart</a>
<a href="#" class="button add_to_cart_button product_type_simple added" onclick="birds()">Add to Cart</a>
<a href="#" class="button add_to_cart_button product_type_simple added" onclick="birds()">Add to Cart</a>
<a href="#" class="button add_to_cart_button product_type_simple added" onclick="birds()">Add to Cart</a>
In actuality, the number of buttons can range from maybe 1-2000 at a time.
css
.button.add_to_cart_button.product_type_simple.added {color:yellow;}
js
function birds(){
var a = document.querySelectorAll('.button.add_to_cart_button.product_type_simple.added' ), i;
for (i = 0; i < a.length; ++i) {
a[i].style.color = "pink";
a[i].innerHTML="Success";
}
setTimeout ( 'cats()', 2000 );
}
function cats(){
var a = document.querySelectorAll('.button.add_to_cart_button.product_type_simple.added' ), i;
for (i = 0; i < a.length; ++i) {
a[i].style.color = "red";
a[i].innerHTML="Add to Cart";
}
}
Here is a page for element inspector: http://s.codepen.io/xkurohatox/debug/eNbMKb?
I have visited this site many times, but never joined until now. Thank you in advance for ANY help! =)