Advertisement
prabapro

Untitled

Dec 28th, 2021 (edited)
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** SHOPIFY CHECKOUT PAGE - GTM JS VARIABLES */
  2.  
  3. //Return the Product_IDs as an array
  4. function() {
  5.   var prods = window.Shopify.checkout.line_items;
  6.   var prod_ids = [];
  7.   var i;
  8.   if (!prods) {
  9.     return;
  10.   }
  11.   for (i = 0; i < prods.length; i++) {
  12.     if (prods[i].product_id) {
  13.       prod_ids.push(prods[i].product_id);
  14.     }
  15.   }
  16.   return prod_ids;
  17. }
  18.  
  19. //Return the Product_IDs as a comma separated list (string)
  20. function() {
  21.   var prods = window.Shopify.checkout.line_items;
  22.   var prod_ids = [];
  23.   var i;
  24.   if (!prods) {
  25.     return;
  26.   }
  27.   for (i = 0; i < prods.length; i++) {
  28.     if (prods[i].product_id) {
  29.       prod_ids.push(prods[i].product_id);
  30.     }
  31.   }
  32.   return prod_ids.join(' , ');
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement