WP Theme / WooCommerce / JS Issue - Cannot read property of undefined.
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Here's the info that I know.. not a JS expert so bear with me.

  • Running the theme Reaction WP by MakeDesign, it's based on SuperSkeleton.
  • Integrating WooCommerce 2.0.3.
  • The store worked with WooCommerce 1.6 and we were able to process orders. Since upgrading to 2.0.3, something changed and there is an issue adding variable products to the cart.
  • The site is running JQuery 1.8.3.
  • If I switch to the TwentyEleven theme, the issue resolves itself.

Live store site: http://www.connectedinmotion.ca/shop/portage-tee/

If you jump into console, you will see the error message:

Uncaught TypeError: Cannot read property '7587' of undefined

Where 7587 is the WP PostID.

The error is obviously within add-to-cart-variation.min.js and passing something back to the page, but I'm not sure what to add.

It would be easier to troubleshoot if you could change the page to include the non-minified version of the JS (which appears to be at http://www.connectedinmotion.ca/wp-content/plugins/woocommerce/assets/js/frontend/add-to-cart-variation.js).
skram 5 years ago
Sorry about that. I overwrote .min with the contents of the non-minified. Faster than finding where the call to .min was coming from. It appears to be on line 130.
Mike 5 years ago
Just confirming - If you change themes, this works flawlessly? That's very weird because the issue seems to occur with the woocommerce plugin which should work the same regardless of the theme, right?
skram 5 years ago
It looks like it has something to do with the product variation feature. Did you follow all the steps here http://docs.woothemes.com/document/product-variations/? The code is looking for a data-attribute called product_variations on the add to cart form which does not exist
sguha 5 years ago
If I switch to the Twenty Eleven theme, the product adds to the cart without issue. No warnings in console. Just made a new test product to ensure it wasn't a problem with the database migration. Same issue.
Mike 5 years ago
awarded to Researcher

Crowdsource coding tasks.

2 Solutions

Winning solution

Script tries to get the product characteristics from the few places, but cannot reach that, as it is defined in a different way.
May be it is an issue of the particular theme or a theme version is old or something else.

I believe the easiest way to make it works properly is to add the next code after the comments on line 128 at add-to-cart-variation.min.js file:

if ( !all_variations )
    all_variations = window["product_variations_" + product_id];
Worked great! Thanks :)
Mike 5 years ago
I don't suppose you guys could help me out - I have a similar problem show here:https://bountify.co/4o
Twayne 5 years ago

Where i put this code in add-to-cart-variation.min.js
please tell me exect position where i will use this code.I am not able to getting 128 line,Please guide me

Thank You!
(WDP jaipur)

View Timeline