jQuery(document).ready(function ($){
var isSimpleBannerTextSet=simpleBannerScriptParams.simple_banner_text!="";
var isSimpleBannerEnabledOnPage = !simpleBannerScriptParams.pro_version_enabled ||
(simpleBannerScriptParams.pro_version_enabled&&!simpleBannerScriptParams.disabled_on_current_page);
var isSimpleBannerVisible=isSimpleBannerTextSet&&isSimpleBannerEnabledOnPage;
if(isSimpleBannerVisible){
if(!simpleBannerScriptParams.wp_body_open||!simpleBannerScriptParams.wp_body_open_enabled){
var closeButton=simpleBannerScriptParams.close_button_enabled ? '<button aria-label="Close" id="simple-banner-close-button" class="simple-banner-button">&#x2715;</button>':'';
var prependElement=document.querySelector(simpleBannerScriptParams.simple_banner_insert_inside_element||'body');
$('<div id="simple-banner" class="simple-banner"><div class="simple-banner-text"><span>'
+ simpleBannerScriptParams.simple_banner_text
+ '</span></div>' + closeButton + '</div>')
.prependTo(prependElement||'body');
}
var bodyPaddingLeft=$('body').css('padding-left')
var bodyPaddingRight=$('body').css('padding-right')
if(bodyPaddingLeft!="0px"){
$('head').append('<style type="text/css" media="screen">.simple-banner{margin-left:-' + bodyPaddingLeft + ';padding-left:' + bodyPaddingLeft + ';}</style>');
}
if(bodyPaddingRight!="0px"){
$('head').append('<style type="text/css" media="screen">.simple-banner{margin-right:-' + bodyPaddingRight + ';padding-right:' + bodyPaddingRight + ';}</style>');
}
function scrollClass(){
var scroll=document.documentElement.scrollTop;
if(scroll > $("#simple-banner").height()){
$("#simple-banner").addClass("simple-banner-scrolling");
}else{
$("#simple-banner").removeClass("simple-banner-scrolling");
}}
document.addEventListener("scroll", scrollClass);
}
function closeBanner(){
if(!simpleBannerScriptParams.keep_site_custom_css&&document.getElementById('simple-banner-site-custom-css')) document.getElementById('simple-banner-site-custom-css').remove();
if(!simpleBannerScriptParams.keep_site_custom_js&&document.getElementById('simple-banner-site-custom-js')) document.getElementById('simple-banner-site-custom-js').remove();
if(document.getElementById('simple-banner-header-margin')) document.getElementById('simple-banner-header-margin').remove();
if(document.getElementById('simple-banner-header-padding')) document.getElementById('simple-banner-header-padding').remove();
if(document.getElementById('simple-banner')) document.getElementById('simple-banner').remove();
}
if(isSimpleBannerVisible){
var sbCookie="simplebannerclosed";
if(simpleBannerScriptParams.close_button_enabled){
if(getCookie(sbCookie)==="true"){
closeBanner();
setCookie(sbCookie, "true", simpleBannerScriptParams.close_button_expiration);
}else{
document.getElementById("simple-banner-close-button").onclick=function(){
closeBanner();
setCookie(sbCookie, "true", simpleBannerScriptParams.close_button_expiration);
};}}else{
if(getCookie(sbCookie)==="true"){
document.cookie="simplebannerclosed=true; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
}}
}
function setCookie(cname,cvalue,expiration){
var d;
if(expiration===''||expiration==='0'||parseFloat(expiration)){
var exdays=parseFloat(expiration)||0;
d=new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
}else{
d=new Date(expiration);
}
var expires="expires=" + d.toUTCString();
document.cookie=cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname){
var name=cname + "=";
var decodedCookie=decodeURIComponent(document.cookie);
var ca=decodedCookie.split(';');
for(var i=0; i < ca.length; i++){
var c=ca[i];
while (c.charAt(0)==' '){
c=c.substring(1);
}
if(c.indexOf(name)==0){
return c.substring(name.length, c.length);
}}
return "";
}
if(simpleBannerScriptParams.pro_version_enabled&&simpleBannerScriptParams.debug_mode){
console.log(simpleBannerScriptParams);
}});
(function ($){
if(awdr_params.refresh_order_review=='1'){
$(document).on('change', 'input[name="payment_method"],input[name="billing_city"],input[name="billing_postcode"]', function (){
refreshCart();
});
$(document).on('blur', 'input[name="billing_email"], select#billing_state', function (){
refreshCart();
});
}
function refreshCart(){
$('body').trigger('update_checkout');
}
$(document).ready(function ($){
function init_events(){
if(awdr_params.enable_update_price_with_qty=='show_dynamically'){
$(document).on('change', '[name="quantity"]', function (){
var awdr_qty_object=$(this);
setTimeout(function(){
var $qty=awdr_qty_object.val();
var $product_id=0;
var $price_place="";
var form=awdr_qty_object.closest("form");
if(form.find('button[name="add-to-cart"]').length){
$product_id=form.find('button[name="add-to-cart"]').val();
var target='div.product p.price';
if(awdr_params.custom_target_simple_product!=undefined){
if(awdr_params.custom_target_simple_product!=""){
target=awdr_params.custom_target_simple_product;
}}
$price_place=$(target).first();
}else if(form.find('input[name="variation_id"]').length){
$product_id=form.find('input[name="variation_id"]').val();
var target='div.product .woocommerce-variation-price';
if(awdr_params.custom_target_variable_product!=undefined){
if(awdr_params.custom_target_variable_product!=""){
target=awdr_params.custom_target_variable_product;
}}
$price_place=$(target);
if(!$(target+' .price').length){
$price_place.html("<div class='price'></div>");
}
$price_place=$(target+' .price')
}
if(!$product_id||$product_id==0){
if(awdr_params.custom_simple_product_id_selector!=undefined){
if(awdr_params.custom_simple_product_id_selector!=""){
let simple_product_id_selector=awdr_params.custom_simple_product_id_selector;
$product_id=$(simple_product_id_selector).val();
let target='div.product p.price';
if(awdr_params.custom_target_simple_product!=undefined){
if(awdr_params.custom_target_simple_product!=""){
target=awdr_params.custom_target_simple_product;
}}
$price_place=$(target).first();
}}
if(awdr_params.custom_variable_product_id_selector!=undefined){
if(awdr_params.custom_variable_product_id_selector!=""){
let variable_product_id_selector=awdr_params.custom_variable_product_id_selector;
$product_id=$(variable_product_id_selector).val();
let target='div.product .woocommerce-variation-price';
if(awdr_params.custom_target_variable_product!=undefined){
if(awdr_params.custom_target_variable_product!=""){
target=awdr_params.custom_target_variable_product;
}}
if(!$(target+' .price').length){
$price_place.html("<div class='price'></div>");
}
$price_place=$(target+' .price')
}}
}
if(!$product_id||!$price_place||$product_id==0){
return;
}
var data={
action: 'wdr_ajax',
method: 'get_price_html',
product_id: $product_id,
qty: $qty,
awdr_nonce: awdr_params.nonce,
};
$.ajax({
url: awdr_params.ajaxurl,
data: data,
type: 'POST',
success: function (response){
if(response.price_html){
$price_place.html(response.price_html)
}else{
if(response.original_price_html!=undefined){
$price_place.html(response.original_price_html)
}}
},
error: function (response){
$price_place.html("")
}});
}, 0);
});
/*$(".single_variation_wrap").on("show_variation", function(event, variation, purchasable){
$(this).closest('form').find('input[name="quantity"]').trigger('change');
});*/
}}
if(awdr_params.js_init_trigger){
$(document).on(awdr_params.js_init_trigger, function (){
init_events();
});
}
init_events();
if(awdr_params.awdr_dynamic_bulk_table_status=="1"){
if(awdr_params.awdr_dynamic_bulk_table_off=="on"){
function awdr_load_variation_table(variation_id){
setTimeout(function(){
if(variation_id!=''&&variation_id!='0'){
var data={
action: 'wdr_ajax',
method: 'get_variable_product_bulk_table',
product_id: variation_id,
awdr_nonce: awdr_params.nonce,
};
let awdr_opacity='div.awdr-bulk-customizable-table';
if(awdr_params.awdr_opacity_to_bulk_table!=undefined){
if(awdr_params.awdr_opacity_to_bulk_table!=""){
awdr_opacity=awdr_params.awdr_opacity_to_bulk_table;
}}
$.ajax({
url: awdr_params.ajaxurl,
data: data,
type: 'POST',
beforeSend: function (){
$(awdr_opacity).css('opacity','0.5');
},
complete: function (){
$(awdr_opacity).css('opacity','1');
},
success: function (response){
if(response.bulk_table){
$('.awdr-bulk-customizable-table').html(response.bulk_table);
}},
error: function (response){
$('.awdr-bulk-customizable-table').html("")
}});
}}, 100);
}
$(".single_variation_wrap").on("hide_variation", function(event){
let variation_id=$(this).closest('form').find('input[name="product_id"]').val();
awdr_load_variation_table(variation_id);
});
$(".single_variation_wrap").on("show_variation", function(event, variation, purchasable){
let variation_id=variation.variation_id;
if(variation.is_bundled!=undefined){
if(variation.is_bundled==true){
return;
}}
awdr_load_variation_table(variation_id);
});
}}
});
})(jQuery);
(function ($){
$.extend({
AdvanceWooDiscountRules: {
form: null,
product_id: null,
quantity: 0,
options: [],
target: null,
getDynamicDiscountPriceFromCartForm: function($form, $target, $options){
if(typeof $options!=='undefined'){
this.options=$options;
}
if(typeof $target!=='undefined'){
this.target=$target;
}
if(typeof $form!=='undefined'&&$form.is('form')){
this.form=$form;
}else{
this.logError("Incorrect form provided");
}
this.product_id=this.getProductIdFromForm();
this.quantity=this.getProductQuantityFromForm();
this.getDiscountPriceForProduct();
},
getDiscountPriceForProduct: function (){
if(this.product_id===null||this.product_id==0){
this.logError("Invalid product");
return [];
}
var data={
action: 'awdr_get_product_discount',
product_id: this.product_id,
qty: this.quantity,
awdr_nonce: awdr_params.nonce,
};
if(typeof this.options.custom_price!=='undefined'){
data.custom_price=this.options.custom_price;
}
var $target=this.target;
var $options=this.options;
$.ajax({
url: awdr_params.ajaxurl,
data: data,
type: 'POST',
success: function (response){
$(document.body).trigger("advanced_woo_discount_rules_on_get_response_for_dynamic_discount", [ response, $target, $options ]);
},
error: function (response){
}});
},
getProductIdFromForm: function (){
var variationIdEl=this.form.find('[name="variation_id"]');
var productIdEl=this.form.find('[name="add-to-cart"]');
if(variationIdEl.length){
return parseInt(variationIdEl.val());
}else if(productIdEl.length){
return parseInt(productIdEl.val());
}
return false;
},
getProductQuantityFromForm: function (){
var $input=this.form.find('input[name="quantity"]');
if($input.length===0){
return 0;
}
return $input.val();
},
logError: function($text){
console.error("Advance discount rule error: %s", $text);
}}
});
})(jQuery);