After updating to 1.6.4, I am getting a js error on single product pages for variable products. After some debugging, it looks like the error is coming from the section that sets $product_img attributes.
It looks like if either o_src or o_title is undefined, the jQuery .attr() function chokes and the chain is broken. A simple solution that works would be to set the o_* variables in the lines immediately preceding this section where the variables are checked.
I'm not 100% confident this isn't some kind of of bug with my template overrides though, so I wanted to ask first before opening a pull request.
Odd they should always be set first. Does this stop the variations working?
Yeah, the rest of the "Add to cart" section isn't even displayed. As it is now, the script checks if each of the o_* variables are set, but it doesn't set them if they aren't. It just sets the corresponding data-* attribute on the $product_img element (see lines 230 - 237). Hopefully that makes sense.
@dominic-p - did you make sure to update the variable.php file in relation to the changes? 40cc7b9
@splashingpixels, sure did, thanks for checking.
@dominic-p - hmmm strange, I am not having issues with this.
Yeah, it does seem like a strange error. As a test, I just disabled all of my custom template overrides in my theme, and I'm still getting the JS error. I'm not sure what to make of it, but it seems like a simple enough fix to make sure the variables are set before we try to use them. What do you think?
@dominic-p - i just install vanilla WP and Woocommerce and using the Free Wootique theme and I am still not able to replicate the issue you're seeing. I can change the variation dropdown just fine and I am not seeing any errors, the add to cart shows after I change the variation and I can click "clear selection" and it would reset just fine. Can you test this again, on a vanilla setup?
Out of curiosity, did you set an image for the variation that you tested? If I create a variable product and set an image for the variation, no JS errors come up. This is the expected result because the part of the code that causes the error is never executed in that scenario.
Maybe I'm just crazy, but I don't see how this code could possibly work if there is no image set for the variation. Going through it line by line:
219 - 221: Set the o_* variables to the values of the current data-o_* attriubtes on the img tag. These will all be undefined if the data attributes don't exist. They won't exist at first because the product-image.php template file doesn't output them.
230 - 237: Check each of the o_* variables. If they evaluate to false, set the corresponding data-o_* attributes, but don't set the o_* variables. The variables will still be undefined at this point.
239: Check if the selected variation has an image assigned to it.
248 - 250: If the variation didn't have an image, set the image src, alt, and title attributes to the values of the corresponding o_* variables which are still undefined because they were never set. jQuery.attr() chokes on the undefined variables and doesn't return the jQuery object, so the chain is broken and we get a type error.
Help me see what I'm missing.
@dominic-p - no, I did not set any images at all, not even the featured image.
I bet your main images isn't inside the product div. Im going to try to break it.
Nope, no luck.
^ try that
@mikejolley, that fixed it. Thanks. I'm still not 100% sure what's causing this, but the fix definitely works and, I think, makes the code a bit more bulletproof.
@mikejolley Weird, I was also getting this error only on one particular install / project, without any template overrides and such...
The same bug seems to affect now some people using the Product Bundles js, so I've filed an Update request for that one, too. :S Weird.
I Got the same issues on my website and need your help. I use Wordpress with Woocommerce / Wootique
The probleme come the variation product and the add to cart button. It s weird because sometimes it work well for the first entry (selection) and if you try again (change the size for example) It doesn't work anymore.
Here 2 picture of my issues http://img15.hostingpics.net/pics/172044clearselectionprobleme.png , http://img15.hostingpics.net/pics/223095addtocartdisable.png
link for the website : http://www.bobbydharrow.com/boutique/authentic-sailor-french-espadrilles/
Thank you in advance ;)
@bobbyde - first please fix your JS errors. Then we can go from there. Upon page load, your site is throwing 2 JS errors. Check your error console.
Having the same issue with no "add to cart" button showing up on variable products.
Prices are set for both attributes
@svenn-aksel - please use http://wordpress.org/support/plugin/woocommerce for support questions. But your issue is your page is not loading the add to cart variation js...