1function klikenFbGetCartItems() { 2 jQuery.post( 3 kkfbFetchCartItems.ajax_url, 4 { 5 action: kkfbFetchCartItems.action, 6 _ajax_nonce: kkfbFetchCartItems.nonce 7 }, 8 function (data) { 9 if (typeof sw !== 'object') return; 10 11 // If no data is available, exit method. 12 if (!data?.cart?.items) return; 13 14 let itemsForGTAG = []; 15 let swCart = []; 16 17 sw.config.currency = kkfbFetchCartItems.currency; 18 19 for (let item in data.cart.items) { 20 itemsForGTAG.push({ 21 "id": `${item.id}`, 22 "name": `${item.name}`, 23 "price": `${item.price}`, 24 "quantity": `${item.quantity}`, 25 "google_business_vertical": "retail" 26 }); 27 28 swCart.push({ 29 "id": `${item.id}`, 30 "name": `${item.name}`, 31 "price": `${item.price}`, 32 "quantity": `${item.quantity}`, 33 "currency": sw.config.currency 34 }); 35 } 36 37 sw.track( 38 "AddToCart", 39 data.event.custom_data, 40 data.event.event_id 41 ); 42 43 sw.gEvent( 44 "add_to_cart", 45 { 46 "items": itemsForGTAG 47 } 48 ); 49 50 sw.register_shopcart( 51 { 52 "items": swCart 53 }); 54 } 55 ); 56} 57 58jQuery(document).ready(function () { 59 // Listen to those events. 60 // 1. added_to_cart: A product is added to cart via AJAX. 61 // 2. updated_cart_totals: Cart info changed, such as product quantity changed, or items being removed (not emptied). 62 jQuery('body').on('added_to_cart updated_cart_totals', function () { 63 klikenFbGetCartItems(); 64 }); 65});
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.