NikolayBezay

Keds event for free shipping campaign new GTM teg.

May 24th, 2021
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.37 KB | None | 0 0
  1. <script>
  2. (function () {
  3.     var FREE_SHIPING_MAX_LIMIT = 199;
  4.     function updateCurrentTotalPrice() {
  5.         var pageTotalPrice = document.querySelector('.minicart-wrapper .subtotal .price');
  6.         if (pageTotalPrice) {
  7.             pageTotalPrice = pageTotalPrice.textContent;
  8.             pageTotalPrice = parseInt(pageTotalPrice.replace('₪', ''));
  9.  
  10.         } else {
  11.             pageTotalPrice = 0;
  12.         }
  13.  
  14.         window.localStorage.setItem('adoricTotalPrice', pageTotalPrice.toFixed(0));
  15.         var event = document.createEvent('Event');
  16.         event.initEvent('adoricTotalCartUpdated', true, true);
  17.         document.querySelector('body').dispatchEvent(event);
  18.         document.querySelector('body').addEventListener('adoricTotalCartUpdated', function (e) {
  19.         }, false);        
  20.     }
  21.     updateCurrentTotalPrice();
  22.     document.querySelector('body').addEventListener('click', function(event) {
  23.         if(event.target.closest('.btn-remove') || event.target.closest('.btn-cart')) {
  24.             updateCurrentTotalPrice();
  25.             setTimeout(updateCurrentTotalPrice, 1500);
  26.             setTimeout(updateCurrentTotalPrice, 4000);
  27.         }
  28.     });
  29.     var addToCartForm = document.querySelector('#product_addtocart_form');
  30.     if (addToCartForm) {
  31.         addToCartForm.addEventListener('submit', updateCurrentTotalPrice);
  32.     }
  33. })();
  34. </script>
Advertisement
Add Comment
Please, Sign In to add comment