function klikenGetCartItems(){
jQuery.post(fetchCartItems.ajax_url, {
action: fetchCartItems.action,
_ajax_nonce: fetchCartItems.nonce
}, function (data){
if(typeof sw!=='object'||!data) return;
let itemsForFBQ=[];
let itemsForGTAG=[];
let swCart=[];
sw.config.currency=fetchCartItems.currency;
for (let item in data){
itemsForFBQ.push({
"id": `${data[item].product_id}`,
"quantity": `${data[item].quantity}`
});
itemsForGTAG.push({
"id": `${data[item].product_id}`,
"name": `${data[item].product_name}`,
"price": `${data[item].price}`,
"quantity": `${data[item].quantity}`,
"google_business_vertical": "retail"
});
swCart.push({
"id": `${data[item].product_id}`,
"name": `${data[item].product_name}`,
"price": `${data[item].price}`,
"quantity": `${data[item].quantity}`,
"currency": sw.config.currency
});
}
sw.track("AddToCart",
{
"content_type": "product",
"contents": itemsForFBQ
});
sw.gEvent("add_to_cart",
{
"items": itemsForGTAG
});
sw.register_shopcart({
"items": swCart
});
});
}
jQuery(document).ready(function (){
jQuery('body').on('added_to_cart updated_cart_totals', function (){
klikenGetCartItems();
});
});