[英]Ajax/Woocommerce - JavaScript - How to get product price having product ID
I need to run JavaScript while adding products to the basket. 我需要在向篮子中添加产品时运行JavaScript。 I have product id (in JavaScript/ajax) and I need to get price of the product (in JavaScript/ajax also). 我有产品ID(在JavaScript / ajax中),我需要获得产品的价格(在JavaScript / ajax中)。
The script uses both variables - product id and product price. 该脚本使用两个变量 - 产品ID和产品价格。
<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>
试试吧:
var price = $('.post-' + dddata + ':eq(0) .amount').text();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.