var mobile = false; if ( window.innerWidth <= 600 ) { mobile = true; kwipped_approve.embedded_app.app_reference.set_minimized_icon_location('170px','-50px'); } else { kwipped_approve.embedded_app.app_reference.set_minimized_icon_location('170px','10px'); } if (window.location.hostname !== "www.kwipped.com" && window.location.pathname != "/checkout" ) { // if (document.querySelector("approve-widget")) { // document.querySelector("approve-widget").remove(); // } // console.log("WIDGET => ",document.querySelectorAll("approve-widget")); // due to the way the approve-widget element has been added and is in the header, it needs to be moved to the body // for consistency and operating inside the visible body element or it will not show if (document.querySelector("approve-widget")) { var widget_tag = document.querySelector("approve-widget"); document.body.appendChild(widget_tag); } // DEBUG MODE -- Set to true if you want console logs to show. var approve_debug_mode = false; if (approve_debug_mode) { console.log("APPROVE SCRIPT LOADED"); } // ****************************************************************** // ****************************************************************** // PRODUCT PAGE // ****************************************************************** // ****************************************************************** // In the easiest implementation, you will be able to set every variable you need right here. // GENERAL PRODUCT WRAPPER -- element to look for to know we are on a product page var approve_product_wrapper_ele = '.productView-details'; var approve_product_wrapper = document.querySelector(approve_product_wrapper_ele); // Must ensure we are on a product page before attempting to select the remaining elements. if (approve_product_wrapper){ // ****************************************************************** // PRODUCT PAGE Variable Configuration // ****************************************************************** // PRODUCT INFO ELEMENTS -- These strings will be used in document.querySelector(). Ensure that there is only one of each on the page. var approve_model_ele_name = '.productView-title'; var approve_price_ele_name = '[data-product-price-without-tax]'; var approve_qty_ele_name = '.form-input--incrementTotal'; // ELEMENT TO INSERT THE BUTTON BELOW -- This strings will be used in document.querySelector(). Ensure that there is only one on the page. // var approve_insert_after_ele_name = '.productView-details .productView-options'; var approve_insert_after_ele_name = ' .form.form--addToCart .form-action:last-child'; // QTY INCREASE / DECREASE BUTTONS -- These buttons do not always trigger a change event on the QTY element. We will add click watchers on these elements. [Optional] var approve_inc_quantity_ele = '[data-action="inc"]'; var approve_dec_quantity_ele = '[data-action="dec"]'; // OPTIONS -- All of the following is optional. Options are be fairly custom // Wrapper for the ENTIRE options section var approve_options_wrapper_ele_name = ' .emthemesModez-productView-optionsGrid'; // Elements that need to have *change* watchers. Mostly used on select elements. Will be used in a foreach, so picking a class with multiple selects is both allowed and encouraged. Ensure these elements are contained within the wrapper above. var approve_radio_ele_name = ' input'; var approve_swatch_ele_name = ' [data-product-attribute="swatch"] input'; var approve_select_ele_name = ' [data-product-attribute="set-select"] select'; // APPROVE BUTTON STYLING var approve_button_display_style = 'inline-block'; // '50px' -- All sides will have margin of 50PX // '50px 10px' -- top/bottom will be 50px, right/left 10px // '50px 10px 20px 30px' -- top / right / bottom / left var approve_button_display_margin = '10px 0px'; var approve_button_to_remove_ele = ""; // ****************************************************************** // END PRODUCT PAGE Variable Configuration // ****************************************************************** // ****************************************************************** // INITIAL PRODUCT PAGE ELEMENT SELECTION -- No Action Required // ****************************************************************** // Grabbing variables based on the variable configuration. // IMPORTANT -- this selection has to be made both INSIDE and OUTSIDE of init_approve_button. // This is because we need to first identify the elements for the use of watchers -- but also need them to be dynamic. // model var approve_model_ele = document.querySelector(approve_model_ele_name); if (!approve_model_ele){ if (approve_debug_mode){ console.warn("APPROVE: No initial approve_model_ele found."); } } // price var approve_price_ele = document.querySelector(approve_price_ele_name); if (!approve_price_ele){ if (approve_debug_mode){ console.warn("APPROVE: No initial approve_price_ele found."); } } // qty if (approve_qty_ele_name){ var approve_qty_ele = document.querySelector(approve_qty_ele_name); if (!approve_qty_ele){ if (approve_debug_mode){ console.warn("APPROVE: No initial approve_qty_ele found."); } } } // element to insert after var approve_insert_after_ele = document.querySelector(approve_insert_after_ele_name); if (!approve_insert_after_ele){ if (approve_debug_mode){ console.warn("APPROVE: No initial approve_insert_after_ele found."); } } // ****************************************************************** // END INITIAL PRODUCT PAGE ELEMENT SELECTION // ****************************************************************** // ****************************************************************** // Initilizes the approve button. // This function handles both the CREATION and UPDATE of button variables // ****************************************************************** function init_approve_button(){ // ****************************************************************** // DYNAMIC PRODUCT PAGE ELEMENT SELECTION -- No Action Required // ****************************************************************** // Grabbing variables based on the variable configuration. // IMPORTANT -- this selection has to be made both INSIDE and OUTSIDE of init_approve_button. // This is because we need to first identify the elements for the use of watchers -- but also need them to be dynamic. // model var approve_model_ele = document.querySelector(approve_model_ele_name); if (!approve_model_ele){ if (approve_debug_mode){ console.error("APPROVE: No dynamic approve_model_ele found."); } return; } var approve_model = approve_model_ele.textContent // price var approve_price_ele = document.querySelector(approve_price_ele_name); if (!approve_price_ele){ if (approve_debug_mode){ console.error("APPROVE: No dynamic approve_price_ele found."); } return; } var approve_price = approve_price_ele.innerHTML.replace(/[^0-9.]/g, ''); approve_price = parseFloat(approve_price); if (!approve_price || approve_price == 0){ if (approve_debug_mode){ console.warn("APPROVE: Price not found (or is 0) after removing non-numerical characters."); } } // qty if (approve_qty_ele_name){ var approve_qty_ele = document.querySelector(approve_qty_ele_name); } if (!approve_qty_ele){ if (approve_debug_mode){ console.warn("APPROVE: No dynamic approve_qty_ele found."); } var approve_qty = 1; } else { var approve_qty = approve_qty_ele.value; } approve_qty = parseInt(approve_qty); // element to insert after var approve_insert_after_ele = document.querySelector(approve_insert_after_ele_name); if (!approve_insert_after_ele){ if (approve_debug_mode){ console.error("APPROVE: No dynamic approve_insert_after_ele found."); } return; } // ****************************************************************** // END DYNAMIC PRODUCT PAGE ELEMENT SELECTION // ****************************************************************** // ****************************************************************** // FIND SELECT OPTIONS // ****************************************************************** if (approve_options_wrapper_ele_name){ // Get options wrapper var approve_options_wrapper_ele = document.querySelector(approve_options_wrapper_ele_name); if (!approve_options_wrapper_ele){ if (approve_debug_mode){ console.log("No approve_options_wrapper_ele found."); } } var approve_checked_options = approve_options_wrapper_ele.querySelectorAll(approve_radio_ele_name); var approve_swatch_options = approve_options_wrapper_ele.querySelectorAll(approve_swatch_ele_name); var approve_selected_options = approve_options_wrapper_ele.querySelectorAll(approve_select_ele_name); if (!approve_checked_options){ if (approve_debug_mode){ console.log("No approve_checked_options found."); } } approve_swatch_options.forEach(function (item, index) { if (item.checked) { var choice = item.getAttribute('data-product-attribute-label'); approve_model += (choice != null ? " | " + choice : ""); } }); approve_checked_options.forEach(function (item, index) { if (item.checked) { var choice = document.querySelector('label[for="'+item.id+'"]'); approve_model += (choice.textContent != null ? " | " + choice.textContent : ""); // console.log(choice); } }); approve_selected_options.forEach(function (item, index) { // console.log(item); if (item.value) { // var choice = document.querySelector('label[for="'+item.id+'"]'); var option = document.querySelector('option[value="'+item.value+'"]'); approve_model += (item.value != null ? " | " + option.textContent : ""); // console.log(choice); } }); } // ****************************************************************** // END SELECT OPTIONS // ****************************************************************** // ****************************************************************** // ADD APPROVE BUTTON TO PAGE // ****************************************************************** // Check if the button is on the page var approve_button = document.getElementById('approve_button_id'); if (!approve_button){ // If event listener is needed for options, here is where it can be initiated. if (approve_options_wrapper_ele_name){ var approve_options_wrapper_ele = document.querySelector(approve_options_wrapper_ele_name); if (approve_options_wrapper_ele){ // If a change listener is needed for options, it is initliazed here. var approve_options1 = approve_options_wrapper_ele.querySelectorAll(approve_select_ele_name); approve_options1.forEach(function (item, index) { item.addEventListener('change',event => { init_approve_button(); }) }); } } // Insert Button= var approve_button = document.createElement('approve-button'); approve_button.id = "approve_button_id"; if (approve_button_display_style){ approve_button.style.display = approve_button_display_style; } if (approve_button_display_margin){ approve_button.style.margin = approve_button_display_margin; } approve_button.setAttribute('application-type',"embedded_app"); approve_button.style.width = "98.4%"; var approve_btn_wrapper = document.createElement("div"); approve_btn_wrapper.appendChild(approve_button); approve_btn_wrapper.style.width = "100%"; approve_insert_after_ele.after(approve_btn_wrapper); } setTimeout(()=>{ var shadow_root = approve_button.shadowRoot; if (shadow_root) { var teaser_wrapper = shadow_root.querySelector(' div[teaser_wrapper]'); var fintext = shadow_root.querySelector(' .finance-text'); teaser_wrapper.style.fontFamily = "Barlow,Arial,Helvetica,sans-serif"; teaser_wrapper.style.textTransform = "uppercase"; teaser_wrapper.style.fontWeight = "600"; fintext.style.fontWeight = "600"; } }, 400); // Removing a button if (approve_button_to_remove_ele){ var approve_button_to_remove = document.querySelector(approve_button_to_remove_ele); if (approve_button_to_remove){ approve_button_to_remove.style.display = "none"; } } // If price is below $200, teaser rate breaks. Let's ensure that it's above $500. if ((parseFloat(approve_price) * parseInt(approve_qty)) < 500){ if (approve_debug_mode){ console.log("Price is below $500."); } approve_button.style.display = "none"; return; } // console.log(approve_price); // console.log(approve_model); // console.log(approve_qty); // Set approve button variables. approve_button.setAttribute('price',approve_price); approve_button.setAttribute('model',approve_model); approve_button.setAttribute('qty',approve_qty); approve_button.setAttribute('type',"new_product"); } // ****************************************************************** // Simple set button qty. Must pass the new QTY to the button. // ****************************************************************** function approve_update_qty(approve_qty){ var approve_button = document.getElementById('approve_button_id'); if (approve_button){ var approve_btn_qty = parseInt(approve_button.getAttribute('qty')); if (approve_qty != approve_btn_qty){ approve_button.setAttribute('qty',approve_qty); } } } // ****************************************************************** // If timing is an issue, this function creates an interval for setting button qty. // ****************************************************************** var approve_timer = null; function approve_update_qty_timer(){ var approve_button = document.getElementById('approve_button_id'); if (approve_button){ if(approve_timer) { clearInterval(approve_timer); approve_timer = null; } var approve_btn_qty = parseInt(approve_button.getAttribute('qty')); var number_of_checks = 0; approve_timer = setInterval(function(){ if(number_of_checks>=5){ clearInterval(approve_timer); approve_timer = null; } if(approve_btn_qty != parseInt(approve_qty_ele.value)){ approve_button.setAttribute('qty',parseInt(approve_qty_ele.value)); clearInterval(approve_timer); approve_timer = null; } number_of_checks++; },500) } } init_approve_button(); // If there is a qty element, we need to set watchers/listeners. if (approve_qty_ele){ // Add change watcher to qty input approve_qty_ele.addEventListener('change',event => { approve_update_qty_timer(); }) if (approve_inc_quantity_ele && approve_dec_quantity_ele){ // buttons that raise or lower the quantity. var approve_qty_btn_inc = document.querySelector(approve_inc_quantity_ele); var approve_qty_btn_dec = document.querySelector(approve_dec_quantity_ele); // Assign click events to these buttons so that qty is updated on click. if (approve_qty_btn_inc && approve_qty_btn_dec){ approve_qty_btn_inc.addEventListener('click',event => { var approve_button = document.getElementById('approve_button_id'); if (approve_button){ var approve_btn_qty = parseInt(approve_button.getAttribute('qty')); approve_btn_qty = approve_btn_qty + 1; approve_update_qty(approve_btn_qty); } }); approve_qty_btn_dec.addEventListener('click',event => { var approve_button = document.getElementById('approve_button_id'); if (approve_button){ var approve_btn_qty = parseInt(approve_button.getAttribute('qty')); if (approve_btn_qty > 1){ approve_btn_qty = approve_btn_qty - 1; approve_update_qty(approve_btn_qty); } } }); } else { if (approve_debug_mode){ console.warn("APPROVE: No approve_qty_btn_inc or approve_qty_btn_dec found."); } } } } if (approve_price_ele){ var approve_price_watcher = approve_price_ele; // Add observer to price element const approve_price_observer = new MutationObserver(function() { init_approve_button(); }); approve_price_observer.observe(approve_price_watcher,{subtree: true, childList: true}); var approve_model_watcher = approve_model_ele; if (approve_model_watcher){ // Add observer to price element const approve_model_observer = new MutationObserver(function() { init_approve_button(); }); approve_model_observer.observe(approve_model_watcher,{subtree: false, childList: true}); } } } else { if (approve_debug_mode){ console.warn("APPROVE: approve_product_wrapper not found.") } } // ****************************************************************** // ****************************************************************** // END PRODUCT PAGE // ****************************************************************** // ****************************************************************** if (window.location.pathname.indexOf("/cart") != -1) { // ****************************************************************** // ****************************************************************** // CART PAGE // ****************************************************************** // ****************************************************************** // ****************************************************************** // CART PAGE Variable Configuration // ****************************************************************** // Element to know we are on the cart page -- ideally a wrapper var approve_cart_wrapper_ele = ".cart-actions"; // Element for each line item var approve_cart_item_ele = '.cart-item'; // Total cart price (optional -- watcher for updating the cart) var approve_cart_total_price_ele = '.cart-contentWrapper' // Item variables var approve_cart_item_model_ele = '.cart-item-name'; var approve_cart_item_price_ele = '.cart-item-info .cart-item-value'; var approve_cart_item_qty_ele = '.form-input.form-input--incrementTotal'; // Insert approve button after this element var approve_cart_insert_btn_after_ele = '.cart-actions #qn-cart-to-quote'; // Element for TAX on cart (optional) var approve_cart_tax_price_ele = ''; // Element for SHIPPING on cart (optional) var approve_cart_shipping_price_ele = ''; // ****************************************************************** // END CART PAGE Variable Configuration // ****************************************************************** // ****************************************************************** // CART PAGE ELEMENT SELECTION -- No Action Required // ****************************************************************** // Find data wrappers -- ideally with syntax so that there will not be a console error thrown on non-cart pages [ie. no multiple query selectors / finds]. function approve_initialize_cart(){ if (approve_cart_wrapper_ele){ var approve_cart_wrapper = document.querySelector(approve_cart_wrapper_ele); var approve_cart_item = document.querySelectorAll(approve_cart_item_ele); } if (!approve_cart_item){ if (approve_debug_mode){ console.log("no cart items found.") } return; } var approve_cart_items_array = []; approve_cart_item.forEach(function (item, index) { var approve_cart_item = {}; // Find model, price, and qty for each cart item. var approve_cart_item_model_wrapper = item.querySelector(approve_cart_item_model_ele); var approve_cart_item_qty_wrapper = item.querySelector(approve_cart_item_qty_ele); var approve_cart_item_price_wrapper = item.querySelector(approve_cart_item_price_ele); console.log(approve_cart_item_price_wrapper); // check model if (!approve_cart_item_model_wrapper){ if (approve_debug_mode){ console.log("No approve_cart_item_model_wrapper found."); } return; } // var approve_cart_item_model_wrapper = approve_cart_item_model_wrapper; // set and encode cart item model. var approve_cart_item_model = approve_cart_item_model_wrapper.textContent.trim(); approve_cart_item.model = encodeURIComponent(approve_cart_item_model); // check price if (!approve_cart_item_price_wrapper){ if (approve_debug_mode){ console.log("No approve_cart_item_price_wrapper found."); } return; } var approve_price = approve_cart_item_price_wrapper.innerHTML.replace(/[^0-9.]/g, ''); var approve_cart_price = parseFloat(approve_price); // set price approve_cart_item.price = approve_cart_price; // check qty if (!approve_cart_item_qty_wrapper){ if (approve_debug_mode){ console.log("No approve_cart_item_qty_wrapper found. Qty is set to 1."); } var approve_qty = 1; } else { var approve_qty = approve_cart_item_qty_wrapper.value; } var approve_cart_qty = parseInt(approve_qty); // set qty approve_cart_item.qty = parseInt(approve_cart_qty); approve_cart_item.type = "new_product"; approve_cart_items_array.push(approve_cart_item); }); // Check to see if the approve button is already on the page. If it isn't, we will create it now. var approve_button = document.getElementById('approve_button_id'); if (!approve_button){ // Find the element where we want to insert our button. var approve_cart_insert_after_ele = document.querySelector(approve_cart_insert_btn_after_ele); if(!approve_cart_insert_after_ele){ if (approve_debug_mode){ console.log("Element to insert approve button after not found."); } return; } var approve_button = document.createElement('approve-button'); approve_button.id = "approve_button_id"; approve_button.style.display="inline-block"; approve_button.style.textAlign="center"; approve_button.style.marginLeft="128px"; approve_button.style.marginTop="20px"; approve_button.setAttribute('application-type',"embedded_app"); approve_button.setAttribute('clear-cart-items',"true"); approve_cart_insert_after_ele.after(approve_button); } if (approve_cart_tax_price_ele){ var approve_tax_price_raw = document.querySelector(approve_cart_tax_price_ele); var approve_tax_price = approve_tax_price_raw.textContent.replace(/[^0-9.]/g, ''); approve_tax_price = parseFloat(approve_tax_price).toFixed(2); if (approve_tax_price && approve_tax_price > 0){ var approve_cart_shipping_item = {}; approve_cart_shipping_item.model = "Tax"; approve_cart_shipping_item.price = approve_tax_price; approve_cart_shipping_item.qty = 1; approve_cart_shipping_item.type = "new_product"; approve_cart_items_array.push(approve_cart_shipping_item); } } if (approve_cart_shipping_price_ele){ var approve_shipping_price_raw = document.querySelector(approve_cart_shipping_price_ele); var approve_shipping_price = approve_shipping_price_raw.textContent.replace(/[^0-9.]/g, ''); approve_shipping_price = parseFloat(approve_shipping_price).toFixed(2); if (approve_shipping_price && approve_shipping_price > 0){ var approve_cart_shipping_item = {}; approve_cart_shipping_item.model = "Shipping"; approve_cart_shipping_item.price = approve_shipping_price; approve_cart_shipping_item.qty = 1; approve_cart_shipping_item.type = "new_product"; approve_cart_items_array.push(approve_cart_shipping_item); } } approve_button.setAttribute('items',JSON.stringify(approve_cart_items_array)); } if (approve_cart_wrapper_ele){ approve_initialize_cart(); var approve_price_watcher = document.querySelector(approve_cart_total_price_ele); // Add observer to price element const approve_price_observer = new MutationObserver(function() { approve_initialize_cart(); }); approve_price_observer.observe(approve_price_watcher,{subtree: true, childList: true}); } else { if (approve_debug_mode){ console.log("No approve_cart_wrapper found."); } } // ****************************************************************** // ****************************************************************** // END CART PAGE // ****************************************************************** // ****************************************************************** } } var load_checkout_page = true; if (load_checkout_page && window.location.hostname !== "www.kwipped.com" && window.location.pathname.indexOf("/checkout") != -1 ) { var approve_debug_mode = false; // due to the way the approve-widget element has been added and is in the header, it needs to be moved to the body // for consistency and operating inside the visible body element or it will not show var original_approve_widget = document.querySelector("approve-widget"); // console.log("APPROVE WIDGET", original_approve_widget); document.body.appendChild(original_approve_widget); // original_approve_widget.remove(); // window.kwipped_approve.embedded_app.app_element = document.body.querySelector("approve-widget"); // window.kwipped_approve.embedded_app.init(); // ****************************************************************** // ****************************************************************** // CHECKOUT PAGE // ****************************************************************** // ****************************************************************** // ****************************************************************** // CHECKOUT PAGE Variable Configuration // ****************************************************************** // Element to know we are on the cart page -- ideally a wrapper var approve_cart_wrapper_ele = ".layout-cart .cart"; // Element for each line item var approve_cart_item_ele = 'section.cart-section'; // Total cart price (optional -- watcher for updating the cart) var approve_cart_total_price_ele = '[data-test="cart-total"] [data-test="cart-price-value"]' // Item variables var approve_cart_item_model_ele = '.product-column.product-body .product-title'; //'.productList-item .product-title'; var approve_cart_item_price_ele = '.product-column.product-actions .product-price[data-test="cart-item-product-price"]'; var approve_cart_item_qty_ele = '[data-test="cart-count-total"]'; // Insert approve button after this element var approve_cart_insert_btn_after_ele = '.layout-cart .cart section.cart-section div .cart-priceItem.cart-priceItem--total'; // Element for TAX on cart (optional) var approve_cart_tax_price_ele = '[data-test="cart-taxes"] [data-test="cart-price-value"]'; // Element for SHIPPING on cart (optional) var approve_cart_shipping_price_ele = '[data-test="cart-shipping"] [data-test="cart-price-value"]'; // ****************************************************************** // END CHECKOUT PAGE Variable Configuration // ****************************************************************** // ****************************************************************** // CHECKOUT PAGE ELEMENT SELECTION -- No Action Required // ****************************************************************** // Find data wrappers -- ideally with syntax so that there will not be a console error thrown on non-cart pages [ie. no multiple query selectors / finds]. function approve_initialize_cart(){ if (approve_cart_wrapper_ele){ var approve_cart_wrapper = document.querySelector(approve_cart_wrapper_ele); var approve_cart_item = document.querySelectorAll(approve_cart_item_ele); } if (!approve_cart_item){ if (approve_debug_mode){ console.log("no cart items found.") } return; } var approve_cart_items_array = []; approve_cart_item.forEach(function (item, index) { var approve_cart_item = {}; // Find model, price, and qty for each cart item. var approve_cart_item_model_wrapper = item.querySelector(approve_cart_item_model_ele); var approve_cart_item_qty_wrapper = item.querySelector(approve_cart_item_qty_ele); var approve_cart_item_price_wrapper = item.querySelector(approve_cart_item_price_ele); console.log(approve_cart_item_price_wrapper); // check model if (!approve_cart_item_model_wrapper){ if (approve_debug_mode){ console.log("No approve_cart_item_model_wrapper found."); } return; } // var approve_cart_item_model_wrapper = approve_cart_item_model_wrapper; // set and encode cart item model. var approve_cart_item_model = approve_cart_item_model_wrapper.textContent.trim(); approve_cart_item.model = encodeURIComponent(approve_cart_item_model); // check price if (!approve_cart_item_price_wrapper){ if (approve_debug_mode){ console.log("No approve_cart_item_price_wrapper found."); } return; } var approve_price = approve_cart_item_price_wrapper.innerHTML.replace(/[^0-9.]/g, ''); var approve_cart_price = parseFloat(approve_price); // set price approve_cart_item.price = approve_cart_price; // check qty if (!approve_cart_item_qty_wrapper){ if (approve_debug_mode){ console.log("No approve_cart_item_qty_wrapper found. Qty is set to 1."); } var approve_qty = 1; } else { var approve_qty = approve_cart_item_qty_wrapper.textContent.replace(/[^0-9]/g,''); } var approve_cart_qty = parseInt(approve_qty); // set qty approve_cart_item.qty = parseInt(approve_cart_qty); approve_cart_item.type = "new_product"; approve_cart_items_array.push(approve_cart_item); }); // Check to see if the approve button is already on the page. If it isn't, we will create it now. var approve_button = document.getElementById('approve_button_id'); if (!approve_cart_button){ // Find the element where we want to insert our button. var approve_cart_insert_after_ele = document.querySelector(approve_cart_insert_btn_after_ele); if(!approve_cart_insert_after_ele){ if (approve_debug_mode){ console.log("Element '"+approve_cart_insert_btn_after_ele+"' to insert approve button after not found."); } return; } var approve_cart_button = document.createElement('approve-button'); approve_cart_button.id = "approve_cart_button_id"; approve_cart_button.style.display="inline-block"; approve_cart_button.style.textAlign="right"; approve_cart_button.style.marginTop="10px"; approve_cart_button.style.marginBottom="15px"; approve_cart_button.style.width="100%"; approve_cart_button.setAttribute('application-type',"embedded_app"); approve_cart_button.setAttribute('clear-cart-items',"true"); approve_cart_insert_after_ele.after(approve_cart_button); } if (approve_cart_tax_price_ele){ var approve_tax_price_raw = document.querySelector(approve_cart_tax_price_ele); var approve_tax_price = approve_tax_price_raw.textContent.replace(/[^0-9.]/g, ''); approve_tax_price = parseFloat(approve_tax_price).toFixed(2); if (approve_tax_price && approve_tax_price > 0){ var approve_cart_shipping_item = {}; approve_cart_shipping_item.model = "Tax"; approve_cart_shipping_item.price = approve_tax_price; approve_cart_shipping_item.qty = 1; approve_cart_shipping_item.type = "new_product"; approve_cart_items_array.push(approve_cart_shipping_item); } } if (approve_cart_shipping_price_ele){ var approve_shipping_price_raw = document.querySelector(approve_cart_shipping_price_ele); var approve_shipping_price = approve_shipping_price_raw.textContent.replace(/[^0-9.]/g, ''); approve_shipping_price = parseFloat(approve_shipping_price).toFixed(2); if (approve_shipping_price && approve_shipping_price > 0){ var approve_cart_shipping_item = {}; approve_cart_shipping_item.model = "Shipping"; approve_cart_shipping_item.price = approve_shipping_price; approve_cart_shipping_item.qty = 1; approve_cart_shipping_item.type = "new_product"; approve_cart_items_array.push(approve_cart_shipping_item); } } approve_cart_button.setAttribute('items',JSON.stringify(approve_cart_items_array)); } if (approve_cart_wrapper_ele){ var approve_checkout_count = 0; function check_checkout_loaded() { if (!document.querySelector(approve_cart_insert_btn_after_ele)) { setTimeout(() => { if (!!document.querySelector(approve_cart_insert_btn_after_ele) && approve_checkout_count < 5 ) { approve_checkout_count ++; return check_checkout_loaded(); } },500); } else { approve_initialize_cart(); } } check_checkout_loaded(); var approve_price_watcher = document.querySelector(approve_cart_total_price_ele); // Add observer to price element const approve_price_observer = new MutationObserver(function() { console.log(111); approve_initialize_cart(); }); approve_price_observer.observe(approve_price_watcher,{subtree: true, childList: true}); } else { if (approve_debug_mode){ console.log("No approve_cart_wrapper found."); } } // ****************************************************************** // ****************************************************************** // END CHECKOUT PAGE // ****************************************************************** // ****************************************************************** }