Within WooCommerce, we want to display additional price information when quantity changes, but only if a variant has a specific attribute associated with it. Is there a way to do this based on the variant object supplied as part of the found_variation event?
$(document).on( 'found_variation', 'form.cart', function( event, variation ) {
/* Your code */
});
Where are you getting the additional price information from? You'll need an Ajax call if it resides in the database (you make your Ajax call in the function body).
Anyway, you can access a variation's attributes in the variation object that found_variation
provides.
To see it, add this to the funtion body (where you currently have /* Your code */
), and open your developer console to see the output. Press F12 in Chrome > go to Console tab.
console.log(variation.attributes);
The attributes are prefixed with 'attribute_pa_'.
If, for example, you want to display something if a variation has the blue color attribute, you'd do this in the function body:
if (variation.attributes.attribute_pa_color === 'blue') {
/* code to display HTML elements with additional price information */
}