.elementor-27 .elementor-element.elementor-element-49ef376{--display:flex;--flex-direction:column;--container-widget-width:100%;--container-widget-height:initial;--container-widget-flex-grow:0;--container-widget-align-self:initial;--flex-wrap-mobile:wrap;}.elementor-27 .elementor-element.elementor-element-c3deead{--display:flex;}.elementor-27 .elementor-element.elementor-element-daea252{width:100%;max-width:100%;margin:0px 0px calc(var(--kit-widget-spacing, 0px) + -20px) 0px;}.elementor-27 .elementor-element.elementor-element-daea252.elementor-element{--order:-99999 /* order start hack */;}.elementor-theme-builder-content-area{height:400px;}.elementor-location-header:before, .elementor-location-footer:before{content:"";display:table;clear:both;}/* Start custom CSS for html, class: .elementor-element-b0936c5 */<!-- NCB Widget Script | UPDATED: 2026-05-21 | NOTES: Auto-detects product ID from WC page — no hardcoded PID. Add to Cart adds correct product + qty to nextdo4me.com cart as individual line items. -->

<script>
(function() {

  /* ── CONFIG ─────────────────────────────────────
     Only this domain ever needs to change.
     Product ID is auto-detected from the WC page.
  ─────────────────────────────────────────────── */
  var CD = 'https://nextdo4me.com';

  /* ── AUTO-DETECT PRODUCT ID ─────────────────────
     Tries every place WooCommerce outputs the PID:
     1. Hidden input[name="add-to-cart"]
     2. add_to_cart button value attribute
     3. wc_add_to_cart_params JS object (WC global)
     4. body class  product-id-XXX
  ─────────────────────────────────────────────── */
  function getProductId() {
    // 1. Hidden input WC puts on every product page
    var inp = document.querySelector('input[name="add-to-cart"]');
    if (inp && inp.value) return parseInt(inp.value, 10);

    // 2. Button value attribute
    var btn = document.querySelector('button.single_add_to_cart_button[value]');
    if (btn && btn.value) return parseInt(btn.value, 10);

    // 3. WooCommerce global JS object
    if (window.wc_add_to_cart_params && window.wc_add_to_cart_params.product_id) {
      return parseInt(window.wc_add_to_cart_params.product_id, 10);
    }

    // 4. Body class  e.g. "postid-45" or "product-id-45"
    var bodyClass = document.body && document.body.className;
    if (bodyClass) {
      var m = bodyClass.match(/(?:postid|product-id)-(\d+)/);
      if (m) return parseInt(m[1], 10);
    }

    return null; // could not detect
  }

  /* ── PRICE DETECTION ────────────────────────────
     Reads WC sale price from the live DOM.
     Sale price (<ins>) always wins over regular.
  ─────────────────────────────────────────────── */
  function getBasePrice() {
    var .elementor-27 .elementor-element.elementor-element-b0936c5s = [
      '.summary .price ins .woocommerce-Price-amount bdi',
      '.summary .price ins .woocommerce-Price-amount',
      '.summary .price .woocommerce-Price-amount bdi',
      '.summary .price .woocommerce-Price-amount'
    ];
    for (var i = 0; i < .elementor-27 .elementor-element.elementor-element-b0936c5s.length; i++) {
      var el = document.querySelector(.elementor-27 .elementor-element.elementor-element-b0936c5s[i]);
      if (el) {
        var val = parseFloat(el.textContent.replace(/[^0-9.]/g, ''));
        if (val > 0) return val;
      }
    }
    return null;
  }

  function formatPrice(n) {
    return '$' + n.toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  }

  /* ── PRICE BUTTONS ──────────────────────────── */
  function updatePriceButtons(base) {
    var tiers = [
      { qty: 1,  disc: 0,    pid: 'ncb-p1',  sid: 'ncb-s1'  },
      { qty: 3,  disc: 0.05, pid: 'ncb-p3',  sid: 'ncb-s3'  },
      { qty: 5,  disc: 0.10, pid: 'ncb-p5',  sid: 'ncb-s5'  },
      { qty: 10, disc: 0.15, pid: 'ncb-p10', sid: 'ncb-s10' }
    ];
    for (var i = 0; i < tiers.length; i++) {
      var t = tiers[i];
      var total = base * t.qty * (1 - t.disc);
      var saved = base * t.qty * t.disc;
      var pEl = document.getElementById(t.pid);
      var sEl = document.getElementById(t.sid);
      if (pEl) pEl.textContent = formatPrice(total);
      if (sEl) sEl.textContent = t.disc > 0 ? 'Save ' + formatPrice(saved) : '\u00a0';
    }
  }

  /* ── MAIN INIT ──────────────────────────────── */
  function ncbInit() {
    var grid  = document.getElementById('ncb-quantity-grid');
    var input = document.getElementById('ncb-qi');
    var plus  = document.getElementById('ncb-plus');
    var minus = document.getElementById('ncb-minus');
    var atc   = document.getElementById('ncb-ab');
    var bn    = document.getElementById('ncb-bn');

    if (!grid || !input || !plus || !minus || !atc || !bn) return false;

    // Detect PID now — page should be fully loaded by this point
    var PID = getProductId();

    var base = getBasePrice();
    if (base) updatePriceButtons(base);

    function updateSelectionUI(val) {
      var btns = document.querySelectorAll('#ncb .qb');
      for (var i = 0; i < btns.length; i++) {
        btns[i].classList.toggle('sel', btns[i].getAttribute('data-qty') == val);
      }
    }

    grid.addEventListener('click', function(e) {
      var btn = e.target.closest('.qb');
      if (!btn) return;
      input.value = btn.getAttribute('data-qty');
      updateSelectionUI(input.value);
    });

    plus.onclick = function(e) {
      e.preventDefault();
      var v = (parseInt(input.value, 10) || 1) + 1;
      input.value = v > 99 ? 99 : v;
      updateSelectionUI(input.value);
    };

    minus.onclick = function(e) {
      e.preventDefault();
      var v = (parseInt(input.value, 10) || 1) - 1;
      input.value = v < 1 ? 1 : v;
      updateSelectionUI(input.value);
    };

    /* ── ADD TO CART ──────────────────────────────
       Adds this product at selected qty to the
       nextdo4me.com WooCommerce cart as its own
       line item. Stays on nextdo4me.com — never
       touches researchhubnow.com.
       If PID not detected, shows an alert so you
       know to check the page setup.
    ─────────────────────────────────────────────── */
    atc.onclick = function() {
      if (!PID) {
        alert('Product ID not detected. Please check WooCommerce product page setup.');
        return;
      }
      var qty = parseInt(input.value, 10) || 1;
      // WC native add-to-cart URL — adds as a line item to the cart
      // then redirects back to the cart page on nextdo4me.com
      window.location.href = CD + '/?add-to-cart=' + PID + '&quantity=' + qty;
    };

    /* ── BUY NOW ────────────────────────────────── */
    bn.onclick = function() {
      if (!PID) {
        alert('Product ID not detected. Please check WooCommerce product page setup.');
        return;
      }
      var qty = parseInt(input.value, 10) || 1;
      window.location.href = CD + '/checkout/?add-to-cart=' + PID + '&quantity=' + qty;
    };

    return true;
  }

  /* ── POLL UNTIL READY ───────────────────────── */
  var ncbAttempts = 0;
  var ncbTimer = setInterval(function() {
    ncbAttempts++;
    if (ncbInit() || ncbAttempts >= 40) clearInterval(ncbTimer);
  }, 100);

})();
</script>/* End custom CSS */