// // Version: 1.2 | Author: Zach | Date: 6/26/2024
// // THIS TEMPLATE IS MEANT TO BE USED WITH BUTTON #90
// // DEBUG MODE -- Set to true if you want console logs to show.
// var approve_debug_mode = true;
// approve_debug_log("APPROVE SCRIPT LOADED");
// // IS MOBILE CHECK
// var mobile = false;
// if ( window.innerWidth <= 600 ) {
// mobile = true;
// }
// // INTEGRATION BUTTON STYLING
// var custom_button_color = "#1F9D00";
// var custom_button_hover_color = "black";
// var custom_button_height = "";
// var custom_button_border = "";
// var custom_button_border_radius = "";
// var custom_background_gradient = "";
// var custom_background_gradient_hover = "";
// var custom_font = "lato, sans-serif";
// var custom_font_color = "";
// var custom_font_size = "14px";
// var custom_text_transform = "uppercase";
// var custom_font_hover_color = "";
// var custom_powered_by_color = "";
// var custom_powered_by_size = "";
// var custom_font_weight = "bold";
// var button_max_width = "370px";
// var button_min_width = "";
// var button_width = "100%";
// var minimum_threshold = null;
// // GENERAL PRODUCT WRAPPER
// var approve_product_wrapper_ele = ' .productView';
// var cart_url_pathname = '/checkout';
// // ******************************************************************
// // PRODUCT PAGE
// // ******************************************************************
// 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){
// // setTimeout(() => {
// // ******************************************************************
// // PRODUCT PAGE 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 = ' .bntest.price.price--withoutTax.VariationProductPrice';
// var approve_qty_ele_name = ' .form-input.form-input--incrementTotal';
// var approve_sku_ele_name = ' .productView-info-value';
// // ELEMENT TO INSERT THE BUTTON BELOW
// var approve_insert_after_ele_name = ' .estimate_date';
// var approve_insert_after_price_text = '';
// // QTY INCREASE / DECREASE BUTTONS
// var approve_inc_quantity_ele = ' .button.button--icon.plus';
// var approve_dec_quantity_ele = ' .button.button--icon.minus';
// // APPROVE BUTTON STYLING
// var approve_button_display_style = 'inline-block';
// var approve_button_wrapper_display_style = 'inline-block';
// // -- top / right / bottom / left
// var approve_button_wrapper_display_margin = '10px 0px 0px 0px';
// var approve_button_display_margin = '0px 0px 0px 0px';
// var approve_price_text_margin = '0px 0px 0px 0px';
// // OPTIONS
// // Wrapper for the ENTIRE options section
// var approve_options_wrapper_ele_name = ' .productView-details.proView_2 div form div .form-field';
// // Select (drop-down) option ele
// var approve_select_ele_name = ' select';
// // Radio (multiple-choice) option ele
// var approve_radio_ele_name = ' input[type="radio"]';
// // CheckBox (check-box) option ele
// var approve_cb_ele_name = ' input[type="checkbox"]';
// // Once the options wrapper is !null template will try all three,
// // Enable neccessary option types:
// var approve_select_on = true;
// var approve_radio_on = false;
// var approve_cb_on = false;
// ////
// // If changes to price and qty arent updating button
// var product_global_watcher = '';
// // ELE TO REMOVE
// var approve_button_to_remove_ele = "";
// // ****************************************
// // END OPTIONAL CONFIG
// // ****************************************
// // ******************************************************************
// // INITIAL PRODUCT PAGE ELEMENT SELECTION -- No Action Required
// // ******************************************************************
// // model
// var approve_model_ele = document.querySelector(approve_model_ele_name);
// if (!approve_model_ele){approve_debug_log("APPROVE: No initial approve_model_ele found.",1);}
// // price
// var approve_price_ele = document.querySelector(approve_price_ele_name);
// if (!approve_price_ele){approve_debug_log("APPROVE: No initial approve_price_ele found.",1);}
// // qty
// if (approve_qty_ele_name){
// var approve_qty_ele = document.querySelector(approve_qty_ele_name);
// if (!approve_qty_ele){approve_debug_log("APPROVE: No initial approve_qty_ele found.",1);}
// }
// if (approve_sku_ele_name){
// var approve_sku_ele = document.querySelector(approve_sku_ele_name);
// if (!approve_sku_ele){approve_debug_log("APPROVE: No initial approve_sku_ele found.",1);}
// }
// // element to insert after
// var approve_insert_after_ele = document.querySelector(approve_insert_after_ele_name);
// if (!approve_insert_after_ele){approve_debug_log("APPROVE: No initial approve_insert_after_ele found.",1);}
// // ******************************************************************
// // END INITIAL PRODUCT PAGE ELEMENT SELECTION
// // ******************************************************************
// function init_approve_button(){
// // ******************************************************************
// // DYNAMIC PRODUCT PAGE ELEMENT SELECTION -- No Action Required
// // ******************************************************************
// // model
// var approve_model_ele = document.querySelector(approve_model_ele_name);
// if (!approve_model_ele){
// approve_debug_log("APPROVE: No dynamic approve_model_ele found.",0,1);
// return;
// }
// var approve_sku_ele = null;
// if (approve_sku_ele_name){
// approve_sku_ele = document.querySelector(approve_sku_ele_name);
// if (!approve_sku_ele){
// approve_debug_log("APPROVE: No dynamic approve_sku_ele found.",1);
// }
// }
// var approve_model = approve_model_ele.textContent;
// if (approve_sku_ele) {
// approve_model += " (SKU: " + approve_sku_ele.textContent.trim() + ") ";
// }
// // price
// var approve_price_ele = document.querySelector(approve_price_ele_name);
// if (!approve_price_ele){
// approve_debug_log("APPROVE: No dynamic approve_price_ele found.",0,1);
// return;
// }
// var approve_price = approve_price_ele.innerHTML.replace(/[^0-9.]/g, '');
// approve_price = parseFloat(approve_price);
// if (!approve_price || approve_price == 0){
// approve_debug_log("APPROVE: Price not found (or is 0) after removing non-numerical characters.",1);
// }
// // qty
// if (approve_qty_ele_name){
// var approve_qty_ele = document.querySelector(approve_qty_ele_name);
// }
// var approve_qty = 1;
// if (!approve_qty_ele){
// approve_debug_log("APPROVE: No dynamic approve_qty_ele found.",1);
// } else {
// 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){
// approve_debug_log("APPROVE: No dynamic approve_insert_after_ele found.",0,1);
// return;
// }
// // ******************************************************************
// // END DYNAMIC PRODUCT PAGE ELEMENT SELECTION
// // ******************************************************************
// // ******************************************************************
// // FIND OPTIONS
// // ******************************************************************
// var approve_options_wrapper_ele = null;
// if (approve_options_wrapper_ele_name){
// // Get options wrapper
// approve_options_wrapper_ele = document.querySelector(approve_options_wrapper_ele_name);
// if (!approve_options_wrapper_ele){
// approve_debug_log("No approve_options_wrapper_ele found.");
// } else {
// // SELECT
// if (approve_select_on) {
// var approve_selected_options = approve_options_wrapper_ele.querySelectorAll(approve_select_ele_name);
// if (!approve_selected_options){
// approve_debug_log("No approve_selected_options found.");
// }
// approve_selected_options.forEach(function (item, index) {
// // CONFIGURE SELECT OPTIONS HERE
// if (item && item.value) {
// var optionValue = document.querySelector('[data-product-attribute-value="' + item.value + '"]')
// approve_model += " | " + optionValue.textContent;
// }
// });
// }
// // RADIO
// if (approve_radio_on) {
// var approve_radioed_options = approve_options_wrapper_ele.querySelectorAll(approve_radio_ele_name);
// if (!approve_radioed_options){
// approve_debug_log("No approve_radioed_options found.");
// }
// approve_radioed_options.forEach(function (item, index) {
// // CONFIGURE RADIO OPTIONS HERE
// if (item && item.checked) {
// approve_model += " | " + item.value;
// }
// });
// }
// // CHECKBOX
// if (approve_cb_on) {
// var approve_checked_options = approve_options_wrapper_ele.querySelectorAll(approve_cb_ele_name);
// if (!approve_checked_options){
// approve_debug_log("No approve_checked_options found.");
// }
// approve_checked_options.forEach(function (item, index) {
// // CONFIGURE RADIO OPTIONS HERE
// if (item && item.checked) {
// var next_sibling = item.nextElementSibling;
// approve_model += " | " + next_sibling.textContent;
// }
// });
// }
// approve_debug_log('Model: '+approve_model + ' Price: ' + approve_price + ' Qty: ' + approve_qty);
// }
// }
// // ******************************************************************
// // 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){
// 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.style.width = button_width;
// approve_button.style.minWidth = button_min_width;
// approve_button.style.maxWidth = button_max_width;
// 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");
// var approve_btn_wrapper = document.createElement("div");
// if (approve_button_wrapper_display_style){
// approve_btn_wrapper.style.display = approve_button_wrapper_display_style;
// }
// if (approve_button_wrapper_display_margin){
// approve_btn_wrapper.style.margin = approve_button_wrapper_display_margin;
// }
// approve_btn_wrapper.appendChild(approve_button);
// approve_btn_wrapper.style.width = "100%";
// approve_insert_after_ele.after(approve_btn_wrapper);
// }
// if (approve_insert_after_price_text) {
// if (!document.querySelector(' .approve-price-teaser-container')) {
// var insert_ele = document.querySelector(approve_insert_after_price_text);
// if (!insert_ele) {
// approve_debug_log("Cant Find price text button insert after ele", 1);
// return;
// }
// let approve_button_wrapper = document.createElement("div");
// approve_button_wrapper.className = "approve-price-teaser-container";
// approve_button_wrapper.style.marginTop = "10px";
// approve_button_wrapper.style.zIndex = "999999999999999";
// approve_button_wrapper.innerHTML = /*html*/`
//
//
//
//
// Business financing for as low as
//
// $
//
// /mo with
//
//
//
// `;
// //button wrapper
// approve_button_wrapper.style.width = "auto";
// approve_button_wrapper.style.display = "inline-block";
// approve_button_wrapper.style.width = "100%";
// if (approve_price_text_margin) approve_button_wrapper.style.margin = approve_price_text_margin;
// var approve_teaser_rate = approve_button_wrapper.querySelector('.teaser-rate');
// var approve_teaser_text = approve_button_wrapper.querySelector('.approve-text-teaser');
// approve_teaser_text.setAttribute('approve-model',approve_model);
// approve_teaser_text.setAttribute('approve-qty',1);
// approve_teaser_text.setAttribute('approve-price',approve_price);
// approve_teaser_text.setAttribute('approve-item-type',"new_product");
// approve_teaser_rate.setAttribute('approve-total',approve_price);
// if (approve_price >= 500){
// insert_ele.after(approve_button_wrapper);
// }
// } else {
// var approve_button_wrapper = document.querySelector(' .approve-price-teaser-container');
// var approve_teaser_rate = approve_button_wrapper.querySelector('.teaser-rate');
// var approve_teaser_text = approve_button_wrapper.querySelector('.approve-text-teaser');
// approve_teaser_text.setAttribute('approve-model',approve_model);
// approve_teaser_text.setAttribute('approve-qty',1);
// approve_teaser_text.setAttribute('approve-price',approve_price);
// approve_teaser_text.setAttribute('approve-item-type',"new_product");
// approve_teaser_rate.setAttribute('approve-total',approve_price);
// }
// window.kwipped_approve.core.activate_approve_teaser_rates();
// }
// if (custom_button_color) approve_button.style.setProperty('--button_color', custom_button_color);
// if (custom_button_hover_color) approve_button.style.setProperty('--button_hover_color', custom_button_hover_color);
// if (custom_button_height) approve_button.style.setProperty('--button_height', custom_button_height);
// if (custom_button_border) approve_button.style.setProperty('--button_border', custom_button_border);
// if (custom_button_border_radius) approve_button.style.setProperty('--button_border_radius', custom_button_border_radius);
// if (custom_font) approve_button.style.setProperty('--button_font', custom_font);
// if (custom_font_color) approve_button.style.setProperty('--button_font_color', custom_font_color);
// if (custom_font_size) approve_button.style.setProperty('--button_font_size', custom_font_size);
// if (custom_text_transform) approve_button.style.setProperty('--button_text_transform', custom_text_transform);
// if (custom_font_hover_color) approve_button.style.setProperty('--button_font_hover_color', custom_font_hover_color);
// if (custom_background_gradient) approve_button.style.setProperty('--button_background_gradient', custom_background_gradient);
// if (custom_background_gradient_hover) approve_button.style.setProperty('--button_background_gradient_hover', custom_background_gradient_hover);
// if (custom_font_weight) approve_button.style.setProperty('--button_font_weight', custom_font_weight);
// if (custom_powered_by_color) approve_button.style.setProperty('--button_powered_by_color', custom_powered_by_color);
// if (custom_powered_by_size) approve_button.style.setProperty('--button_powered_by_size', custom_powered_by_size);
// // 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";
// }
// }
// // 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");
// // If price is below $200, teaser rate breaks. Let's ensure that it's above $500.
// if ((parseFloat(approve_price) * parseInt(approve_qty)) < (minimum_threshold ? minimum_threshold : 2500)){
// approve_debug_log("Price is below $2500.");
// approve_button.style.display = "none";
// return;
// }
// }
// // ******************************************************************
// // 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){
// activate_increase_and_decrease_buttons();
// }
// }
// 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});
// }
// }
// if (product_global_watcher) {
// var approve_global_watcher = document.querySelector(product_global_watcher);
// if (approve_global_watcher){
// // Add observer to price element
// const approve_global_observer = new MutationObserver(function() {
// init_approve_button();
// });
// approve_global_observer.observe(approve_global_watcher,{subtree: true, childList: true});
// }
// }
// // },500);
// }
// else {
// approve_debug_log("APPROVE: approve_product_wrapper not found.",1)
// }
// /**
// * Activates quantity buttons.
// * QTY buttons are, sometimes added to the page after a page has been rendered. This will wait for that to happen.
// */
// function activate_increase_and_decrease_buttons(number_of_tries=0){
// number_of_tries++;
// // buttons that raise or lower the quantity.
// var approve_inc_quantity_ele = ' .button.button--icon.plus';
// var approve_dec_quantity_ele = ' .button.button--icon.minus';
// var approve_qty_btn_inc = document.querySelector(approve_inc_quantity_ele);
// var approve_qty_btn_dec = document.querySelector(approve_dec_quantity_ele);
// if ((!approve_qty_btn_inc || !approve_qty_btn_dec) && number_of_tries < 10){
// setTimeout(()=>(activate_increase_and_decrease_buttons(number_of_tries)),500);
// return
// }
// // 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 {
// approve_debug_log("APPROVE: No approve_qty_btn_inc or approve_qty_btn_dec found.",1);
// }
// }
// // ******************************************************************
// // ******************************************************************
// // END PRODUCT PAGE
// // ******************************************************************
// // ******************************************************************
// // ******************************************************************
// // CART PAGE
// // ******************************************************************
// if (window.location.pathname == cart_url_pathname) {
// var approve_wrapper_align = "";
// var approve_wrapper_margin = "10px 0px 0px 0px";
// var button_width = "176%";
// var button_min_width = "";
// var button_max_width = "603px";
// var custom_button_border_radius = "3px";
// // ******************************************************************
// // CART PAGE Variable Configuration
// // ******************************************************************
// // Element to know we are on the cart page -- ideally a wrapper
// var approve_cart_wrapper_ele = " .remove-checkout-step-numbers";
// // Element for each line item
// var approve_cart_item_ele = ' .productList';
// // Total cart price (optional -- watcher for updating the cart)
// var approve_cart_total_price_ele = ' [data-test="cart-total"] div span.cart-priceItem-value'
// // Item variables
// var approve_cart_item_model_ele = ' .product-title.optimizedCheckout-contentPrimary';
// var approve_cart_item_price_ele = ' .product-price.optimizedCheckout-contentPrimary';
// var approve_cart_item_qty_ele = '';
// var approve_cart_sku = '';
// // Insert approve button after this element
// var approve_cart_insert_btn_after_ele = ' #checkout-payment-continue';
// var approve_cart_global_watcher = ' .checkout-step.optimizedCheckout-checkoutStep.checkout-step--payment';
// // Element for cart item options
// var approve_cart_model_option_ele = ' .product-option';
// // Element for TAX on cart (optional)
// var approve_cart_tax_price_ele = ' [data-test="cart-taxes"] div span.cart-priceItem-value span';
// // Element for SHIPPING on cart (optional)
// var approve_cart_shipping_price_ele = ' [data-test="cart-shipping"] div span.cart-priceItem-value span';
// // ******************************************************************
// // 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);
// if (approve_cart_sku) var approve_cart_item_sku_wrapper = item.querySelector(approve_cart_sku);
// // 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();
// if (approve_cart_item_sku_wrapper) approve_cart_item_model += " (SKU: " + approve_cart_item_sku_wrapper.textContent.trim() + ")";
// if (approve_cart_model_option_ele) {
// var options = item.querySelectorAll(approve_cart_model_option_ele);
// if (!options) {
// approve_debug_log("No approve cart item options found.");
// } else {
// options.forEach(function(item, index) {
// approve_cart_item_model += " | " + item.textContent;
// });
// }
// }
// // approve_cart_item.model = encodeURIComponent(approve_cart_item_model);
// approve_cart_item.model = 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_item.qty = 1;
// 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_cart_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');
// var approve_button_wrapper = document.createElement('div');
// approve_button_wrapper.appendChild(approve_button);
// approve_button.id = "approve_cart_button_id";
// if (approve_wrapper_align) approve_button_wrapper.style.textAlign = approve_wrapper_align;
// if (approve_wrapper_margin) approve_button_wrapper.style.margin = approve_wrapper_margin;
// if (button_width) approve_button.style.width = button_width;
// if (button_min_width) approve_button.style.minWidth = button_min_width;
// if (button_max_width) approve_button.style.maxWidth = button_max_width;
// approve_button.style.display="inline-block";
// approve_button.setAttribute('application-type',"embedded_app");
// approve_button.setAttribute('clear-cart-items',"true");
// approve_cart_insert_after_ele.after(approve_button_wrapper);
// }
// if (custom_button_color) approve_button.style.setProperty('--button_color', custom_button_color);
// if (custom_button_hover_color) approve_button.style.setProperty('--button_hover_color', custom_button_hover_color);
// if (custom_button_height) approve_button.style.setProperty('--button_height', custom_button_height);
// if (custom_button_border) approve_button.style.setProperty('--button_border', custom_button_border);
// if (custom_button_border_radius) approve_button.style.setProperty('--button_border_radius', custom_button_border_radius);
// if (custom_font) approve_button.style.setProperty('--button_font', custom_font);
// if (custom_font_color) approve_button.style.setProperty('--button_font_color', custom_font_color);
// if (custom_font_size) approve_button.style.setProperty('--button_font_size', custom_font_size);
// if (custom_text_transform) approve_button.style.setProperty('--button_text_transform', custom_text_transform);
// if (custom_font_hover_color) approve_button.style.setProperty('--button_font_hover_color', custom_font_hover_color);
// if (custom_font_weight) approve_button.style.setProperty('--button_font_weight', custom_font_weight);
// if (custom_powered_by_color) approve_button.style.setProperty('--button_powered_by_color', custom_powered_by_color);
// // Remove powered by text
// let shadow_host_ele = ' #approve_cart_button_id';
// let shadow_host = document.querySelector(shadow_host_ele);
// let shadow_root = shadow_host.shadowRoot;
// let powered_by_text_ele = ' .powered-by';
// let powered_by_text = shadow_root.querySelector(powered_by_text_ele);
// powered_by_text.remove();
// 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);
// // Checks to see if shipping is free since website shows free shipping with text and not 0
// if (document.querySelector(approve_cart_shipping_price_ele).textContent !== "Free"){
// 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);
// }
// }
// }
// console.log(approve_cart_items_array);
// approve_button.setAttribute('items',JSON.stringify(approve_cart_items_array));
// }
// if (approve_cart_wrapper_ele){
// approve_initialize_cart();
// if (approve_cart_global_watcher) {
// var approve_global_watcher = document.querySelector(approve_cart_global_watcher);
// // Add observer to price element
// const approve_global_observer = new MutationObserver(function() {
// approve_initialize_cart();
// });
// approve_global_observer.observe(approve_global_watcher,{subtree: true, childList: true});
// }
// } else {
// if (approve_debug_mode){
// approve_debug_log("No approve_cart_wrapper found.", 1);
// }
// }
// // ******************************************************************
// // ******************************************************************
// // END CART PAGE
// // ******************************************************************
// // ******************************************************************
// }
// // ******************************************************************
// // ******************************************************************
// // END CART PAGE
// // ******************************************************************
// // ******************************************************************
// // IF YOU WANT TO USE A LOG WITH COLORS YOU CAN USE
// function approve_debug_log(log, warn, err) {
// warn = warn || false;
// err = err || false;
// let css = "padding: 5px 20px; ";
// if (err) {
// css += "background:#8B0000; color:#fff; ";
// } else if(warn) {
// css += "background:#FFBF00; color:#000; ";
// } else {
// css += "background:#418AC9; color:#fff; ";
// }
// if (approve_debug_mode) console.log("%c"+log,css);
// }