Advertisement
NikolayBezay

Sebocalm check cart total price and show campaigns.

Apr 15th, 2021
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.07 KB | None | 0 0
  1. <script>
  2. (function() {
  3.    function checkCartTotalPrice(pageSubtotal) {
  4.         localStorage.setItem('pageTotalPrice', pageSubtotal);
  5.         var MINIMUM_CART_TOTAL = 50;
  6.         var MAXIMUM_CART_TOTAL = 140;
  7.         if (pageSubtotal > MINIMUM_CART_TOTAL && pageSubtotal < MAXIMUM_CART_TOTAL) {
  8.           window.pageTotalPrice = pageSubtotal;
  9.            adoric && adoric.trigger('showByMinimalPrice');
  10.         }
  11.         MINIMUM_CART_TOTAL = 299;  
  12.         if (pageSubtotal < MINIMUM_CART_TOTAL) {
  13.           adoric && adoric.trigger('showForLes299Price');
  14.        }
  15.  
  16.    }
  17.    function addToCartCustomHandler(){
  18.        setTimeout(function() {
  19.            var URL = 'https://www.sebocalm.co.il/cart/';
  20.            var parser = new DOMParser();
  21.            var doc =  '';
  22.            var data = null;
  23.            var xhr = new XMLHttpRequest();
  24.            xhr.withCredentials = true;
  25.            xhr.addEventListener('readystatechange', function () {
  26.                if (this.readyState === 4) {
  27.                    doc = parser.parseFromString(this.responseText, 'text/html');      
  28.                    var pageSubtotal = doc.querySelector('.bag-total > .woocommerce-Price-amount.amount');
  29.                     if (pageSubtotal) {
  30.                         pageSubtotal = pageSubtotal.textContent.replace('₪','').replace(',','');
  31.                         checkCartTotalPrice(parseFloat(pageSubtotal));
  32.                     }
  33.                 }
  34.             });
  35.             xhr.open('GET', URL);
  36.             xhr.setRequestHeader('cache-control', 'no-cache');
  37.             xhr.send(data);
  38.         }, 1500);
  39.     }
  40.     addToCartCustomHandler();
  41.     var addToCartButtonType1 = document.querySelector('.add-to-cart-btn');
  42.     var addToCartButtonType2 = document.querySelectorAll('.add_to_cart_button');
  43.     if (addToCartButtonType1) {
  44.         addToCartButtonType1.addEventListener('click', addToCartCustomHandler);
  45.     }
  46.     for(var i = 0; i < addToCartButtonType2.length; i++ ) {
  47.       addToCartButtonType2[i].addEventListener('click', addToCartCustomHandler);
  48.   }
  49. })();
  50. </script>
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement