Чтобы отследить событие — добавление товара в корзину через Ajax, используем функцию:
$('body').on('added_to_cart',function(){
// здесь пишем код, который хотим выполнить после добавления товара в корзину
});
теперь поработаем с передаваемыми данными:
(function($){
$(document.body).on('added_to_cart', function( event, fragments, cart_hash, button ) {
var product_id = button.data('product_id'), // Get the product id
product_qty = button.data('quantity'), // Get the quantity
product_sku = button.data('product_sku'), // Get the product sku
product_name = button.data('product_name'), // Get the product name
product_price = button.data('product_price'), // Get the product price
currency = button.data('currency'); // Get the currency
bianoTrack('track', 'add_to_cart', {
id: 'PRODUCT-'+product_id,
quantity: product_qty,
unit_price: product_price,
currency: currency,
});
// For testing: View all product available data on console log (to be removed)
console.log( button.data() );
});
})(jQuery);