I need to run JavaScript while adding products to the basket. I have product id (in JavaScript/ajax) and I need to get price of the product (in JavaScript/ajax also).
The script uses both variables - product id and product price.
<script>
(function($){
$('body').on( 'added_to_cart', function(e, fragments, cart_hash, this_button){
var dddata = $(this_button).data('product_id');
console.log(dddata);
});
})(jQuery);
</script>
Try it:
var price = $('.post-' + dddata + ':eq(0) .amount').text();