P
P
PM2018-07-11 17:34:24
WordPress
PM, 2018-07-11 17:34:24

How to get the price and name of a product variation?

The variable product card has a link with attributes data-variation-titleanddata-variation-price

TYK
<a class="btn" data-variation-title="" data-variation-price="" href="#">Заказать</a>

data-variation-titleHow can I transfer the values ​​(name and data-variation-priceprice) of the selected product variation to this link in attributes ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
its2easyy, 2018-07-12
@jimmykoks

If I understand correctly, then this should be done on the product page when selecting all the attributes of the variations, then the selected variation can be obtained like this:

$( '.variations_form' ).each( function() {
       $(this).on( 'found_variation', function( event, variation ) {
            console.log(variation);
        });
});

found_variation is triggered when all the necessary attributes are selected, after that, the necessary data can be taken from the variation variable and written to the link. But the variation object does not store the product names and attribute names, but only the variation id and attribute slug, so as an option, you can use the script to take the product name from somewhere on the page and add the value of the selected selects with attributes to it and then use it as you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question