1function klikenGetCartItems() { 2 jQuery.post(fetchCartItems.ajax_url, { 3 action: fetchCartItems.action, 4 _ajax_nonce: fetchCartItems.nonce 5 }, function (data) { 6 // If no data is available, exit method. 7 if (typeof sw !== 'object' || !data) return; 8 9 let itemsForFBQ = []; 10 let itemsForGTAG = []; 11 let swCart = []; 12 13 sw.config.currency = fetchCartItems.currency; 14 15 for (let item in data) { 16 itemsForFBQ.push({ 17 "id": `${data[item].product_id}`, 18 "quantity": `${data[item].quantity}` 19 }); 20 21 itemsForGTAG.push({ 22 "id": `${data[item].product_id}`, 23 "name": `${data[item].product_name}`, 24 "price": `${data[item].price}`, 25 "quantity": `${data[item].quantity}`, 26 "google_business_vertical": "retail" 27 }); 28 29 swCart.push({ 30 "id": `${data[item].product_id}`, 31 "name": `${data[item].product_name}`, 32 "price": `${data[item].price}`, 33 "quantity": `${data[item].quantity}`, 34 "currency": sw.config.currency 35 }); 36 } 37 38 sw.track("AddToCart", 39 { 40 "content_type": "product", 41 "contents": itemsForFBQ 42 }); 43 44 sw.gEvent("add_to_cart", 45 { 46 "items": itemsForGTAG 47 }); 48 49 sw.register_shopcart( 50 { 51 "items": swCart 52 }); 53 }); 54} 55 56jQuery(document).ready(function () { 57 // Listen to those events. 58 // 1. added_to_cart: A product is added to cart via AJAX. 59 // 2. updated_cart_totals: Cart info changed, such as product quantity changed, or items being removed (not emptied). 60 jQuery('body').on('added_to_cart updated_cart_totals', function () { 61 klikenGetCartItems(); 62 }); 63});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.