jQuery(function($){
'use strict';
$(document).ready(function(){
var notice_timeout=2000;
if(WPT_DATA.notice_timeout){
notice_timeout=WPT_DATA.notice_timeout;
}
if(typeof $('.wpt-wrap .search_select').select2==='function'&&$('.wpt-wrap .search_select').length > 0&&WPT_DATA.select2!=='disable'){
var select2Object={};
var multiple=$('.wpt-wrap .search_select').attr('multiple');
if(WPT_DATA.search_select_placeholder!==''&&multiple=='multiple'){
select2Object={
placeholder: WPT_DATA.search_select_placeholder,
allowClear: true,
};}
$('.wpt-wrap .search_select.query').select2(select2Object);
$('.keyword-s-wrapper select').select2();
}
var windowWidth=$(window).width();
$(window).resize(function(){
if(windowWidth!=$(window).width()&&WPT_DATA.resize_loader){
location.reload();
return;
}});
$('.item_inside_cell').each(function(){
var style=$(this).attr('style');
$(this).children('a').attr('style',style);
$(this).attr('style','');
});
if(!$('div.wpt-wrap .wpt-table-tag').hasClass('wpt_product_table')){
return false;
}
var plugin_url=WPT_DATA.plugin_url;
var include_url=WPT_DATA.include_url;
var content_url=WPT_DATA.content_url;
var ajax_url=WPT_DATA.ajax_url;
var site_url=WPT_DATA.site_url;
if(ajax_url==='undefined'){
return false;
}
$('body').on('click','.wpt_table_pagination.pagination_loading a',function(e){
e.preventDefault();
return false;
});
setTimeout(function(){
$('.wpt-table-tag.wpt_product_table .wpt-td-tag select').trigger('change');
}, 4000);
function fixAfterAjaxLoad(){
$('.wpt-table-tag.wpt_product_table .wpt-td-tag select').trigger('change');
$.getScript(include_url + "/js/mediaelement/wp-mediaelement.min.js");
$.getScript(plugin_url + "/woocommerce/assets/js/frontend/add-to-cart.js");
$.getScript(plugin_url + "/woocommerce/assets/js/frontend/woocommerce.js");
$.getScript(plugin_url + "/woocommerce/assets/js/frontend/add-to-cart-variation.min.js");
}
$(document.body).on('wpt_ajax_loaded',function(){
var variableProducts,musicProducts;
setTimeout(function(){
variableProducts=$('.wpt-tr-tag.product_type_variable').length;
musicProducts=$('audio,.wp-audio-shortcode').length;
if(variableProducts > 0){
$.getScript(plugin_url + "/woocommerce/assets/js/frontend/add-to-cart-variation.min.js");
}
if(musicProducts > 0){
$.getScript(include_url + "/js/mediaelement/wp-mediaelement.min.js");
$(window.wp.mediaelement.initialize);
}},100);
});
var config_json=$('#wpt_table').data('config_json');
if(typeof config_json==='undefined'){
return false;
}
function getConfig_json(temp_number){
var temp_cjson=$('div#table_id_' + temp_number + ' #wpt_table').data('config_json');
if(typeof temp_cjson==='undefined'){
temp_cjson=config_json;
}
return temp_cjson;
}
var footer_cart=config_json.footer_cart;
var footer_cart_size=config_json.footer_cart_size;
var footer_possition=config_json.footer_possition;
var footer_bg_color=config_json.footer_bg_color;
$('body').append("<div class='wpt_notice_board'></div>");
$('body').append('<div style="height: ' + footer_cart_size + 'px;width: ' + footer_cart_size + 'px;" class="wpt-footer-cart-wrapper '+ footer_possition +' '+ footer_cart +'"><a target="_blank" href="#" class="wpt-footer-cart-wrapper-sssss"></a></div>');
function WPT_NoticeBoard(){
var noticeBoard=$('div.wpt_notice_board');
$.ajax({
type: 'POST',
url: ajax_url,
data: {
action: 'wpt_print_notice'
},
success: function(response){
if(config_json.popup_notice!=='1'||config_json.popup_notice=='no') return;
var eachNoticeInnter=$(response);
eachNoticeInnter.css('display','none');
if(response!==''){
noticeBoard.append(eachNoticeInnter);
eachNoticeInnter.fadeIn();
setTimeout(function(){
eachNoticeInnter.fadeOut('medium');
eachNoticeInnter.remove();
},notice_timeout);
}},
error: function(){
console.log("Unable to load Notice");
return false;
}});
}
$('body').on('click','div.wpt_notice_board>div',function(){
$(this).fadeOut('medium');
});
$('div.wpt_checked_table').each(function(){
var temp_number=$(this).data('temp_number');
$('div.wpt_checked_table .all_check_header input.wpt_check_universal.wpt_check_universal_header').trigger('click');
$('div.wpt_checked_table th input.wpt_check_universal').trigger('click');
$('body.wpt_table_body .wpt-wrap input.enabled.wpt_tabel_checkbox.wpt_td_checkbox').trigger('click');
updateCheckBoxCount(temp_number);
});
function WPT_MiniCart(){
}
$(document.body).trigger('updated_cart_totals');
$(document.body).trigger('wc_fragments_refreshed');
$(document.body).trigger('wc_fragments_refresh');
$(document.body).trigger('wc_fragment_refresh');
WPT_MiniCart();
$('body').on('click', '.wpt-wrap .wpt_thumbnails_popup img', function(){
var thisImg=$(this);
var image_width, final_image_url, variation_id,imgSize;
variation_id=$(this).attr('data-variation_id');
if('undefined'!==typeof variation_id){
var data_objec=$(this).closest('.wpt-tr-tag.wpt-row').data('product_variations');
var finalImgObject,fullObject;
$.each(data_objec,function(index,eachObj){
if(variation_id==eachObj['variation_id']){
fullObject=eachObj;
finalImgObject=eachObj['image'];
}});
if('undefined'!==typeof finalImgObject){
final_image_url=finalImgObject.full_src;
image_width=finalImgObject.full_src_w;
IMG_Generator(thisImg,final_image_url, image_width);
}}else{
image_width=$(this).parent().data('width');
final_image_url=$(this).parent().data('url');
IMG_Generator(thisImg,final_image_url, image_width);
}});
function IMG_Generator(thisImg,final_image_url, image_width){
var image_height, product_title,placeholder_image,wrapper_style;
image_height='auto';
if('undefined'===typeof final_image_url){
placeholder_image=$(thisImg).attr('src');
console.log("No Thumbnail Image found");
final_image_url=placeholder_image;
wrapper_style='';
}else{
wrapper_style="style='width: " + image_width + "px; height:" + image_height + "px'";
}
product_title=$(thisImg).closest('.wpt-tr-tag.wpt-row').find('.wpt_product_title_in_td').text();
if(!product_title){
product_title='';
}
var html='<div id="wpt_thumbs_popup" class="wpt_thumbs_popup"><div class="wpt_popup_image_wrapper" ' + wrapper_style + '><span title="Close" id="wpt_popup_close">&times;</span><h2 class="wpt_wrapper_title">' + product_title + '</h2><div class="wpt_thums_inside">';
html +='<img class="wpt_popup_image" src="' + final_image_url + '">';
html +='</div></div></div>';
if($('body').append(html)){
var PopUp=$('.wpt_thumbs_popup, #wpt_thumbs_popup');
PopUp.fadeIn('slow');
var Wrapper=$('div.wpt_popup_image_wrapper');
Wrapper.fadeIn();
}}
$('body').on('click', '.wpt_popup_image_wrapper', function(){
return false;
});
$('body').on('click', '#wpt_thumbs_popup span#wpt_popup_close, #wpt_thumbs_popup', function(){
$('#wpt_thumbs_popup').fadeOut(function(){
$(this).remove();
});
});
$('body').on('click','a.button.wpt_woo_add_cart_button.outofstock_add_to_cart_button.disabled',function(e){
e.preventDefault();
var temp_number=$(this).closest('.wpt_action').data('temp_number');
config_json=getConfig_json(temp_number);
showAlert(config_json.sorry_out_of_stock);
return false;
});
function footerCartAnimation(){
$('a.wpt-view-n .wpt-bag').addClass('wpt-spin4 animate-spin');
$('.wpt-new-footer-cart').addClass('wpt-fcart-anim');
$('.wpt-fcart-coll-expand').addClass('animated');
}
function footerCartAnimationStop(){
$('a.wpt-view-n .wpt-bag').removeClass('wpt-spin4 animate-spin');
$('.wpt-new-footer-cart').removeClass('wpt-fcart-anim');
$('.wpt-fcart-coll-expand').removeClass('animated');
}
$(document.body).on('click', 'a.ajax_active.wpt_variation_product.single_add_to_cart_button.button.enabled, a.add_to_cart_button.ajax_add_to_cart, a.ajax_active.add_to_cart_button.wpt_woo_add_cart_button', function(e){
e.preventDefault();
var thisButton=$(this);
if(thisButton.hasClass('disabled')){
return;
}
thisButton.addClass('disabled');
var data={};
$.each(thisButton.data(), function(key, value){
data[ key ]=value;
});
$(document).trigger('adding_to_cart', [ thisButton, data ]);
var thisRow=$(this).closest('.wpt_row');
var messageBox=thisRow.find('.wpt_custom_message');
var product_id=thisRow.data('product_id');
var temp_number=$(this).closest('#product_id_' + product_id).data('temp_number');
config_json=getConfig_json(temp_number);
var qtyElement=$('#table_id_' + temp_number + ' #product_id_' + product_id + ' input.input-text.qty.text');
var min_quantity=qtyElement.attr('min');
if(typeof min_quantity==='undefined'&&!WPT_DATA.return_zero){
min_quantity=1;
}
if(WPT_DATA.return_zero==='1'){
min_quantity=0;
}
var checkoutURL=WPT_DATA.checkout_url;//$('#table_id_' + temp_number).data('checkout_url');
var cartURL=WPT_DATA.cart_url;//$('#table_id_' + temp_number).data('cart_url');
var quantity=$(this).attr('data-quantity');
var wpt_custom_message=$('#table_id_' + temp_number + ' #wpt_table.wpt-table-tag .wpt_row_product_id_' + product_id + ' .wpt_message .message').val();
var variation_id=$(this).attr('data-variation_id');
var variation=$(this).attr('data-variation');
if(variation){
variation=JSON.parse(variation);
}
if(! quantity||quantity==='0'){
thisButton.removeClass('disabled');
alert("Sorry! 0 Quantity");
return;
}
footerCartAnimation();
var Bubble=thisRow.find('.wpt_ccount');
if(Bubble.length==0){
thisRow.find('a.add_to_cart_button').append('<span class="wpt_ccount wpt_ccount_' + product_id + '"><i class="wpt-spin5 animate-spin"></span>');
}else{
Bubble.html('<i class="wpt-spin5 animate-spin">');
}
var get_data=$(this).attr('href') + '&quantity=' + quantity;
var additional_json=$('#table_id_' + temp_number + ' #wpt_table.wpt-table-tag .wpt-tr-tag.wpt_row_product_id_' + product_id).attr('additional_json');
var data={
action:     'wpt_ajax_add_to_cart',
variation:  variation,
variation_id:   variation_id,
product_id: product_id,
quantity:   quantity,
wpt_custom_message: wpt_custom_message,
additional_json: additional_json,
};
$.ajax({
type: 'POST',
url: ajax_url,
data: data,
complete: function(){
$(document).trigger('wc_fragment_refresh');
$(document).trigger('cart_page_refreshed');
$(document).trigger('cart_totals_refreshed');
$(document).trigger('wc_fragments_refreshed');
$('.wpt_row_product_id_' + product_id + ' .input-text').trigger('change');
$(document.body).trigger('update_checkout');
},
success: function(response){
thisButton.removeClass('disabled');
thisButton.addClass('added');
messageBox.val('');
var argStats={};
argStats['status']=true;
argStats['product_id']=product_id;
argStats['variation_id']=variation_id;
argStats['variation']=variation;
argStats['temp_number']=temp_number;
argStats['table_id']=temp_number;
$(document.body).trigger('wpt_adding_to_cart',argStats);
$(document.body).trigger('updated_cart_totals');
$(document.body).trigger('wc_fragments_refreshed');
$(document.body).trigger('wc_fragments_refresh');
$(document.body).trigger('wc_fragment_refresh');
$(document.body).trigger('added_to_cart');
if(WPT_DATA.return_quanity){
qtyElement.val(min_quantity);
thisButton.attr('data-quantity',min_quantity);
}
WPT_NoticeBoard();
if(config_json.product_direct_checkout==='yes'){
window.location.href=checkoutURL;
}
if(config_json.product_direct_checkout==='cart'){
window.location.href=cartURL;
}
var argStats={};
argStats['status']=true;
argStats['product_id']=product_id;
argStats['variation_id']=variation_id;
argStats['variation']=variation;
argStats['temp_number']=temp_number;
argStats['table_id']=temp_number;
$(document.body).trigger('wpt_added_to_cart',argStats);
},
error: function(){
alert('Failed - Unable to add by ajax');
},
});
});
function showAlert(alertMessage){
if(typeof alertMessage=='string'){
var tempMsg=alertMessage.trim();
if(tempMsg.length!==0){
WPTControl.showNotification(alertMessage, 'error', 'top_right', 4000);
}}else{
let errMsgErr="You have inserted " + typeof alertMessage + " Variable. But should be a String.";
WPTControl.showNotification(errMsgErr, 'error', 'top_right', 2000);
console.log(errMsgErr);
}}
$('body').on('click', 'a.wpt_variation_product.single_add_to_cart_button.button.disabled,a.disabled.yith_add_to_quote_request.button', function(e){
e.preventDefault();
var temp_number=$(this).closest('.wpt_action').data('temp_number');
config_json=getConfig_json(temp_number);
showAlert(config_json.no_right_combination);
return false;
});
$('body').on('click', 'a.wpt_woo_add_cart_button.button.disabled.loading,a.disabled.yith_add_to_quote_request.button.loading', function(e){
e.preventDefault();
var temp_number=$(this).closest('.wpt_action').data('temp_number');
config_json=getConfig_json(temp_number);
showAlert(config_json.adding_in_progress);
return false;
});
$(document.body).on('change','.wpt_varition_section',function(){
var product_id=$(this).data('product_id');
var temp_number=$(this).data('temp_number');
config_json=getConfig_json(temp_number);
var target_class='#product_id_' + product_id;
var quoted_target='yith_request_temp_' + temp_number + '_id_' + product_id;
var targetRightCombinationMsg=config_json.right_combination_message;
var selectAllItemMessage=config_json.select_all_items_message;
var outOfStockMessage=config_json.out_of_stock_message;
var targetThumbs=$('#table_id_' + temp_number + ' #product_id_' + product_id + ' .wpt_thumbnails img');
var targetThumbsTd=$('#table_id_' + temp_number + ' #product_id_' + product_id + ' .wpt_thumbnails');
var htmlStored=targetThumbsTd.attr('data-html_stored');
var targetThumbsText,targetThumbsTextSRCSET;
if(htmlStored!=='added'){
targetThumbsText=targetThumbs.attr('src');
targetThumbsTextSRCSET=targetThumbs.attr('srcset');
targetThumbsTd.attr('data-html',targetThumbsText);
targetThumbsTd.attr('data-html_srcset',targetThumbsTextSRCSET);
}
targetThumbsTd.attr('data-html_stored','added');
var targetThumbsSRC=targetThumbsTd.attr('data-html');
var targetThumbsSRCSET=targetThumbsTd.attr('data-html_srcset');
var variations_data=$(this).closest(target_class).data('product_variations');
var messageSelector=$(this).children('div.wpt_message');
var addToCartSelector=$('#table_id_' + temp_number + ' #product_id_' + product_id + ' a.wpt_variation_product.single_add_to_cart_button');
var rowSelector=$('#table_id_' + temp_number + ' #product_id_' + product_id);
var addToQuoteSelector=$('.' + quoted_target);
var checkBoxSelector=$('.wpt_check_temp_' + temp_number + '_pr_' + product_id);
var autoCheckBoxObj=$('div.wpt_checked_table input.wpt_check_temp_' + temp_number + '_pr_' + product_id);
function targetTD(td_name){
var targetElement=$('#table_id_' + temp_number + ' #product_id_' + product_id + ' .wpt_' + td_name);
return targetElement;
}
function setValueToTargetTD_IfAvailable(target_td_name, gotten_value){
if(gotten_value!==""){
targetTD(target_td_name).html(gotten_value);
}}
function setValueToTargetTD(target_td_name, gotten_value){
targetTD(target_td_name).html(gotten_value);
}
function getValueFromOldTD(target_td_name, datas_name){
var product_descrition_old=targetTD(target_td_name).data(datas_name);
targetTD(target_td_name).html(product_descrition_old);
}
var current={};
var additionalAddToCartUrl='';
var quote_data='';
$(this).find('select').each(function(){
var attribute_name=$(this).data('attribute_name');
var attribute_value=$(this).val();
current[attribute_name]=attribute_value;
additionalAddToCartUrl +='&' + attribute_name + '=' + attribute_value;
});
if($.isEmptyObject(variations_data)){
targetRightCombinationMsg=config_json.right_combination_message_alt;//"Product variations is not set Properly. May be: price is not inputted. may be: Out of Stock.";
}
var targetVariationIndex='not_found';
var selectAllItem=true;
try{
variations_data.forEach(function(attributesObject, objectNumber){
$.each(current,function(key,value){
if(value==="0"){
selectAllItem=false;
}});
var total_right_combination=0, total_combinationable=0;
if(selectAllItem){
$.each(attributesObject.attributes,function(key,value){
if(value===""||value===current[key]){
total_right_combination++;
}
total_combinationable++;
});
if(total_right_combination===total_combinationable){
targetVariationIndex=parseInt(objectNumber);
}}else{
targetRightCombinationMsg=selectAllItemMessage; //"Please select all Items.";
}});
}catch(e){
}
var price_markup_backup=targetTD('price').attr('data-price_markup');
if(! price_markup_backup){
var targetPriceHTML=targetTD('price').find('span').prop('innerHTML');
targetTD('price').attr('data-price_markup', targetPriceHTML);
}
var wptMessageText=false;
if(targetVariationIndex!=='not_found'){
var targetAttributeObject=variations_data[targetVariationIndex];
additionalAddToCartUrl +='&variation_id=' + targetAttributeObject.variation_id;
quote_data=additionalAddToCartUrl;
additionalAddToCartUrl=addToCartSelector.data('add_to_cart_url') + additionalAddToCartUrl;
addToCartSelector.attr('href', additionalAddToCartUrl);
if(targetAttributeObject.is_in_stock){
disbale_enable_class();
}else{
targetRightCombinationMsg=outOfStockMessage; //"Out of Stock";
enable_disable_class();
}
addToCartSelector.attr('data-variation', JSON.stringify(current)); //current_object //targetAttributeObject.attributes //It was before 2.8 now we will use 'current' object whic will come based on current_selection of variations
addToCartSelector.attr('data-variation_id', targetAttributeObject.variation_id);
rowSelector.attr('data-variation', JSON.stringify(current)); //current_object //targetAttributeObject.attributes //It was before 2.8 now we will use 'current' object whic will come based on current_selection of variations
rowSelector.attr('data-variation_id', targetAttributeObject.variation_id);
addToQuoteSelector.attr('data-variation', JSON.stringify(current)); //targetAttributeObject.attributes //It was before 2.8 now we will use 'current' object whic will come based on current_selection of variations
addToQuoteSelector.attr('data-variation_id', targetAttributeObject.variation_id);
addToQuoteSelector.attr('data-quote_data', quote_data);
wptMessageText=targetAttributeObject.availability_html;
setValueToTargetTD_IfAvailable('price', targetAttributeObject.price_html);
targetThumbs.attr('src', targetAttributeObject.image.gallery_thumbnail_src);
if(targetAttributeObject.image.srcset&&'false'!==targetAttributeObject.image.srcset){
targetThumbs.attr('srcset', targetAttributeObject.image.srcset);
};
setValueToTargetTD_IfAvailable('sku', targetAttributeObject.sku);
setValueToTargetTD_IfAvailable('stock', targetAttributeObject.availability_html);
var targetQty=$('#table_id_' + temp_number + ' #product_id_' + product_id + ' input.input-text.qty.text').val();
if(!targetQty){
targetQty=1;
}
var targetCurrency=targetTD('total_item').data('currency');
var targetPriceDecimalSeparator=targetTD('total_item').data('price_decimal_separator');
var targetPriceThousandlSeparator=targetTD('total_item').data('thousand_separator');
var targetNumbersPoint=targetTD('total_item').data('number_of_decimal');
var totalPrice=parseFloat(targetQty) * parseFloat(targetAttributeObject.display_price);
totalPrice=totalPrice.toFixed(targetNumbersPoint);
var priceFormat=WPT_DATA.priceFormat;
var newPrice;
switch (priceFormat){
case 'left':
newPrice=targetCurrency+ (totalPrice + '').replace(/\B(?=(?:\d{3})+\b)/g, targetPriceThousandlSeparator);
break;
case 'right':
newPrice=(totalPrice + '').replace(/\B(?=(?:\d{3})+\b)/g, targetPriceThousandlSeparator) + targetCurrency;
break;
case 'left-space':
newPrice=targetCurrency + ' ' +  (totalPrice + '').replace(/\B(?=(?:\d{3})+\b)/g, targetPriceThousandlSeparator);
break;
case 'right-space':
newPrice=(totalPrice + '').replace(/\B(?=(?:\d{3})+\b)/g, targetPriceThousandlSeparator) + ' ' + targetCurrency;
break;
}
var totalPriceHtml='<strong>' + newPrice + '</strong>';
setValueToTargetTD_IfAvailable('total_item',totalPriceHtml);
targetTD('total').attr('data-price', targetAttributeObject.display_price);
targetTD('total').addClass('total_general');
setValueToTargetTD_IfAvailable('description', targetAttributeObject.variation_description);
var finalWeightVal=targetAttributeObject.weight * targetQty;
finalWeightVal=finalWeightVal.toFixed(2);
if(finalWeightVal==='NaN'){
finalWeightVal='';
}
targetTD('weight').attr('data-weight',targetAttributeObject.weight);
setValueToTargetTD_IfAvailable('weight', finalWeightVal);
setValueToTargetTD_IfAvailable('height', targetAttributeObject.dimensions.height);
setValueToTargetTD_IfAvailable('length', targetAttributeObject.dimensions.length);
setValueToTargetTD_IfAvailable('width', targetAttributeObject.dimensions.width);
targetThumbs.attr('data-variation_id', targetAttributeObject.variation_id);
if(!autoCheckBoxObj.is(":checked")){
autoCheckBoxObj.trigger('click');
}
updateCheckBoxCount(temp_number);
targetAttributeObject['status']=true;
targetAttributeObject['product_id']=product_id;
targetAttributeObject['temp_number']=temp_number;
targetAttributeObject['table_id']=temp_number;
try{
$(document.body).trigger('wpt_changed_variations',targetAttributeObject);
}catch(error){
console.log("Variation ID not founded. To see error, Please console.log(error) here.");
}}else{
targetThumbs.attr('src', targetThumbsSRC);
targetThumbs.attr('srcset', '');
targetThumbs.removeAttr('data-variation_id');
addToCartSelector.attr('data-variation', false);
addToCartSelector.attr('data-variation_id', false);
rowSelector.attr('data-variation', false);
rowSelector.attr('data-variation_id', false);
addToQuoteSelector.attr('data-variation', false);
addToQuoteSelector.attr('data-variation_id', false);
addToQuoteSelector.attr('data-quote_data', false);
wptMessageText='<p class="wpt_warning warning">' + targetRightCombinationMsg + '</p>'; //Please choose right combination. //Message will come from targatted tables data attribute //Mainly for WPML issues
enable_disable_class();
targetPriceHTML=targetTD('price').attr('data-price_markup');
targetTD('price').html(targetPriceHTML);
getValueFromOldTD('sku', 'sku');
setValueToTargetTD('total_item', '');
targetTD('total_item').attr('data-price', '');
targetTD('total_item').removeClass('total_general');
getValueFromOldTD('description', 'product_description');
var oldBackupWeight=targetTD('weight').attr('data-weight_backup');
targetTD('weight').attr('data-weight',oldBackupWeight);
var oldWeightVal=oldBackupWeight * targetQty;
setValueToTargetTD_IfAvailable('weight', oldWeightVal);
getValueFromOldTD('length', 'length');
getValueFromOldTD('width', 'width');
getValueFromOldTD('height', 'height');
if(autoCheckBoxObj.is(":checked")){
autoCheckBoxObj.prop("checked", false);;
}
updateCheckBoxCount(temp_number);
var argStats={};
argStats['status']=false;
argStats['product_id']=product_id;
argStats['temp_number']=temp_number;
argStats['table_id']=temp_number;
$(document.body).trigger('wpt_changed_variations',argStats);
}
messageSelector.html(wptMessageText);
function enable_disable_class(){
addToCartSelector.removeClass('enabled');
addToCartSelector.addClass('disabled');
rowSelector.removeClass('enabled');
rowSelector.addClass('disabled');
addToQuoteSelector.removeClass('enabled');
addToQuoteSelector.addClass('disabled');
checkBoxSelector.removeClass('enabled');
checkBoxSelector.addClass('disabled');
}
function disbale_enable_class(){
addToCartSelector.removeClass('disabled');
addToCartSelector.addClass('enabled');
rowSelector.removeClass('disabled');
rowSelector.addClass('enabled');
addToQuoteSelector.removeClass('disabled');
addToQuoteSelector.addClass('enabled');
checkBoxSelector.removeClass('disabled');
checkBoxSelector.addClass('enabled');
}});
$('.wpt_varition_section').each(function(){
var current_value=$(this).children('select').val();
if(current_value!=='0'){
$(this).trigger('change');
}});
$('body').on('click', 'input.wpt_tabel_checkbox.wpt_td_checkbox.disabled', function(e){
e.preventDefault();
var temp_number=$(this).data('temp_number');
config_json=getConfig_json(temp_number);
showAlert(config_json.sorry_plz_right_combination);
return false;
});
$('div.normal_table_wrapper a.button.add_to_cart_all_selected').click(function(){
footerCartAnimation();
var temp_number=$(this).data('temp_number');
var allMessageBox=$('#table_id_' + temp_number + ' .wpt_custom_message');
config_json=getConfig_json(temp_number);
var checkoutURL=WPT_DATA.checkout_url;
var cartURL=WPT_DATA.cart_url;
var currentAllSelectedButtonSelector=$('#table_id_' + temp_number + ' a.button.add_to_cart_all_selected');
var tableWrapperTag=$('#table_id_' + temp_number + ' .wpt_table_tag_wrapper');
currentAllSelectedButtonSelector.addClass('disabled');
currentAllSelectedButtonSelector.addClass('loading');
tableWrapperTag.addClass('wpt-ajax-loading');
var add_cart_text=$('#table_id_' + temp_number).data('basic_settings').add_to_cart;
var products_data={};
var itemAmount=0;
$('#table_id_' + temp_number + ' input.enabled.wpt_tabel_checkbox.wpt_td_checkbox:checked').each(function(){
var thisRow=$(this).closest('.wpt-tr-tag.wpt-row');
var product_id=$(this).data('product_id');
var thisButton=$('.wpt-tr-tag.wpt_row_product_id_' + product_id + ' wpt_action a.button.wpt_woo_add_cart_button');
thisButton.removeClass('added');
thisButton.addClass('disabled');
thisButton.addClass('loading');
var qtyElement=$('#table_id_' + temp_number + ' #product_id_' + product_id + ' input.input-text.qty.text');
var min_quantity=qtyElement.attr('min');
if(min_quantity==='0'||typeof min_quantity==='undefined'){
min_quantity=1;
}
var currentAddToCartSelector=$('#table_id_' + temp_number + ' #product_id_' + product_id + ' .wpt_action a.wpt_woo_add_cart_button');
var currentCustomMessage=$('#table_id_' + temp_number + ' #product_id_' + product_id + ' .wpt_message .message').val();
var additional_json=thisRow.attr('additional_json');
var currentVariaionId=thisRow.attr('data-variation_id');//currentAddToCartSelector.data('variation_id');
var currentVariaion;
try{
currentVariaion=$.parseJSON(thisRow.attr('data-variation'));
}catch(e){
}
var currentQantity=$('#table_id_' + temp_number + ' #wpt_table.wpt-table-tag .product_id_' + product_id).attr('data-quantity');
currentQantity=parseFloat(currentQantity);
if(currentQantity <=0){
return;
}
products_data[product_id]={
product_id: product_id,
quantity: currentQantity,
variation_id: currentVariaionId,
variation: currentVariaion,
wpt_custom_message: currentCustomMessage,
additional_json:additional_json
};
var items=$('#table_id_' + temp_number + ' tr#product_id_' + product_id).attr('data-quantity');
items=parseFloat(items);
if(items <=0){
return;
}
var itemCountSystem=config_json.item_count;
if(typeof itemCountSystem!=='undefined'&&itemCountSystem==='all'){
itemAmount +=items;
}else{
itemAmount++;
}});
if(itemAmount < 1){
currentAllSelectedButtonSelector.removeClass('disabled');
currentAllSelectedButtonSelector.removeClass('loading');
tableWrapperTag.removeClass('wpt-ajax-loading');
footerCartAnimationStop();
showAlert(config_json.please_choose_items);
return false;
}
uncheckAllCheck(temp_number);
currentAllSelectedButtonSelector.html(add_cart_text + ' [ ' + config_json.loading_more_text + ' ]');
$.ajax({
type: 'POST',
url: ajax_url,
data: {
action: 'wpt_ajax_mulitple_add_to_cart',
products: products_data,
},
complete: function(){
$(document).trigger('wc_fragments_refreshed');
$(document.body).trigger('update_checkout');
},
success: function(response){
$(document.body).trigger('updated_cart_totals');
$(document.body).trigger('wc_fragments_refreshed');
$(document.body).trigger('wc_fragments_refresh');
$(document.body).trigger('wc_fragment_refresh');
currentAllSelectedButtonSelector.html(add_cart_text + ' [ ' + itemAmount + ' ' + config_json.add2cart_all_added_text + ' ]');
if(config_json.all_selected_direct_checkout==='yes'){
window.location.href=checkoutURL;
return;
}else if(config_json.all_selected_direct_checkout==='cart'){
window.location.href=cartURL;
return;
}
currentAllSelectedButtonSelector.removeClass('disabled');
currentAllSelectedButtonSelector.removeClass('loading');
tableWrapperTag.removeClass('wpt-ajax-loading');
WPT_NoticeBoard();
$('#table_id_' + temp_number + ' input.enabled.wpt_tabel_checkbox.wpt_td_checkbox:checked').each(function(){
var product_id=$(this).data('product_id');
var qtyElement,min_quantity;
qtyElement=$('#table_id_' + temp_number + ' #product_id_' + product_id + ' input.input-text.qty.text');
min_quantity=qtyElement.attr('min');
if(min_quantity==='0'||typeof min_quantity==='undefined'){
min_quantity=1;
}
qtyElement.val(min_quantity);
var messageBox=$(this).closest('.wpt-row').find('.wpt_custom_message');
messageBox.val('');
});
},
error: function(){
alert('Failed');
},
});
});
$('body').append('<style>div.wpt-footer-cart-wrapper>a:after,div.wpt-footer-cart-wrapper>a{background-color: ' + footer_bg_color + ';}</style>');
function oneSecondDelay(f, delay){
var timer=null;
return function(){
var context=this, args=arguments;
clearTimeout(timer);
timer=window.setTimeout(function(){
f.apply(context, args);
},
delay||500);
};}
$('.query_box_direct_value').keyup(oneSecondDelay(function(){
var thisID=$(this).attr('id');
var temp_number=thisID.replace('single_keyword_','');
$('#wpt_query_search_button_' + temp_number).trigger('click');
}));
$('body').on('change','.search_select',function(){
var thisID=$(this).parents('.wpt-wrap').attr('id');
var temp_number=thisID.replace('table_id_','');
$('#wpt_query_search_button_' + temp_number).trigger('click');
});
$('body').on('change,focus','.query_box_direct_value',function(){
var thisID=$(this).parents('.wpt-wrap').attr('id');
var temp_number=thisID.replace('table_id_','');
$('#wpt_query_search_button_' + temp_number).trigger('click');
});
$('body').on('change','select.query_box_direct_value',function(){
var thisID=$(this).parents('.wpt-wrap').attr('id');
var temp_number=thisID.replace('table_id_','');
$('#wpt_query_search_button_' + temp_number).trigger('click');
});
function generate_url_by_search_query(table_id=0, extra=''){
config_json=getConfig_json(table_id);
if(config_json.query_by_url!=='1'){
return;
}
var key,value;
var link=window.location.origin + window.location.pathname + "?table_ID=" + table_id + "&";
$('.query_box_direct_value').each(function(){
key=$(this).attr('data-key');
if(key==='s'){
key='search_key';
}
value=$(this).val();
if(value!==''){
link +=key + "=" + value + "&";
}});
var page_number=$('#table_id_' + table_id + ' table').attr('data-page_number');
page_number=parseInt(page_number) - 1;
link +="page_number=" + page_number;
$('a.search_box_reset').show();
link +=extra;
window.history.pushState('data', null, link.replace(/(^&)|(&$)/g, ""));
}
$(document.body).on('wpt_ajax_load_data',function(Event,data){
var table_id=data.table_id;
var page_number=data.others.page_number;
var extra_link_tax_cf="";
if(typeof data.args.tax_query==='object'&&!$.isEmptyObject(data.args.tax_query)){
extra_link_tax_cf="&tax=" + convertToSimpleFormat(data.args.tax_query);
}
if(typeof data.args.meta_query==='object'&&!$.isEmptyObject(data.args.meta_query)){
extra_link_tax_cf="&meta=" + convertToSimpleFormat(data.args.meta_query);
}
generate_url_by_search_query(table_id, extra_link_tax_cf);
});
function convertToSimpleFormat(obj){
const parts=[];
for (const key in obj){
const terms=obj[key].terms;
if(Array.isArray(terms)){
parts.push(`${key}-${terms.join(',')}`);
}else{
parts.push(`${key}-${terms}`);
}}
return parts.join('__');
}
$('body').on('change','select.filter_select',function(){
var temp_number=$(this).data('temp_number');
var paginatedMiniFilter=$('.wpt-variable-product-options').length;
if(paginatedMiniFilter > 0){
return;
}
filterTableRow(temp_number);
});
$('body').on('click','a.wpt_filter_reset',function(e){
e.preventDefault();
var temp_number=$(this).data('temp_number');
$('#table_id_' + temp_number + ' select.filter_select').each(function(){
$(this).prop('selectedIndex', 0);
});
$('#table_id_' + temp_number + ' select.filter_select').trigger('change');
$('.wpt-my-pagination-' + temp_number).show();
});
function filterTableRow(temp_number){
emptyInstanceSearchBox(temp_number);
uncheckAllCheck(temp_number);
var filterBoxYesNo=$('#table_id_' + temp_number + ' .wpt-mini-filter').html();
let tableBodyobj=$('#table_id_' + temp_number + ' #wpt_table.wpt-table-tag tbody');
var ClassArray=[];
var serial=0;
$('#table_id_' + temp_number + ' .wpt-mini-filter select.filter_select').each(function(){
var currentClass=$(this).val();
if(currentClass!==''){
ClassArray[serial]='.' + currentClass;
serial++;
}});
var finalClassSelctor='.filter_row' + ClassArray.join('');
var hideAbleClass='#table_id_' + temp_number + ' table .wpt-tr-tag.wpt_row';
let foundRow=$(finalClassSelctor);
let foundFirstRow=foundRow.first();
let colSpanCount=tableBodyobj.find('.wpt-tr-tag').first().find('td.td_or_cell').length;
let foundRowCount=foundRow.length;
let notFundMsg=config_json.product_not_founded;
if(foundRowCount > 0){
$('.wpt-my-pagination-' + temp_number).hide();
}
$('#table_id_' + temp_number + ' #wpt_table.wpt-table-tag tbody .wpt-tr-tag.product-not-found-tr').remove();
if(foundRowCount < 1){
let newRotHtml="<tr class='product-not-found-tr'><td colspan='" + colSpanCount + "'><div class='wpt_product_not_found'>" + notFundMsg + "</div></td></tr>";
$('#table_id_' + temp_number + ' #wpt_table.wpt-table-tag tbody').append(newRotHtml)
}
if(filterBoxYesNo){
$(hideAbleClass + ' wpt_check input.enabled.wpt_tabel_checkbox').removeClass('wpt_td_checkbox');
$(hideAbleClass).css('display','none');
$(hideAbleClass).removeClass('visible_row');
$(finalClassSelctor).fadeIn();
$(finalClassSelctor).addClass('visible_row');
$(finalClassSelctor + ' wpt_check input.enabled.wpt_tabel_checkbox').addClass('wpt_td_checkbox');
}
updateCheckBoxCount(temp_number);
}
$('body').on('change', '.wpt_row .message', function(){
var temp_number=$(this).parents('.wpt-tr-tag.wpt_row').data('temp_number');
var msg=$(this).val();
var product_id=$(this).parents('.wpt-tr-tag').data('product_id');
var thisRow='#table_id_' + temp_number + ' .wpt-tr-tag.product_id_' + product_id;
$(thisRow + ' .message').val(msg);
});
$(document).on('keyup','.wpt_row input.input-text.qty.text', oneSecondDelay(inputBoxChangeHandle,1500));
$(document.body).on('change', '.wpt_row input.input-text.qty.text', inputBoxChangeHandle);
function inputBoxChangeHandle(){
var temp_number=$(this).parents('.wpt-tr-tag.wpt_row').data('temp_number');
var Qty_Val=$(this).val();
var product_id=$(this).parents('.wpt-tr-tag').data('product_id');
var thisRow='#table_id_' + temp_number + ' .wpt-tr-tag.product_id_' + product_id;
var outofstockVal=$(thisRow).hasClass("stock_status_outofstock");
if(outofstockVal){
Qty_Val=0;
}
$(thisRow).find('.yith-ywraq-add-to-quote input.input-text.qty.text').val(Qty_Val);
$(thisRow).attr('data-quantity', Qty_Val);
$(thisRow + ' .wpt_action a.wpt_woo_add_cart_button').attr('data-quantity', Qty_Val);
$(thisRow + ' .wpt_action a.add_to_cart_button').attr('data-quantity', Qty_Val);
$(thisRow + ' .wpt_buy_link a.add_to_cart_button').attr('data-quantity', Qty_Val);
var Item_URL='?add-to-cart=' + product_id + '&quantity=' + Qty_Val;
$(thisRow + ' .wpt_action a.add_to_cart_button').attr('href', Item_URL);
var targetTotalSelector=$('#table_id_' + temp_number + ' .product_id_' + product_id + ' .wpt_total_item.total_general');
var targetWeightSelector=$('#table_id_' + temp_number + ' .product_id_' + product_id + ' .weight-box');
var targetWeightAttr=$('#table_id_' + temp_number + ' .product_id_' + product_id + ' .weight-box').attr('data-weight');
var totalWeight=parseFloat(targetWeightAttr) * parseFloat(Qty_Val);
totalWeight=totalWeight.toFixed(2);
if(totalWeight==='NaN'){
totalWeight='';
}
targetWeightSelector.html(totalWeight);
var targetTotalStrongSelector=$('#table_id_' + temp_number + ' .product_id_' + product_id + ' .wpt_total_item.total_general strong');
var targetPrice=targetTotalSelector.attr('data-price');
var targetCurrency=targetTotalSelector.data('currency');
var targetPriceDecimalSeparator=targetTotalSelector.data('price_decimal_separator');
var targetPriceThousandlSeparator=targetTotalSelector.data('thousand_separator');
var targetNumbersPoint=targetTotalSelector.data('number_of_decimal');
var totalPrice=parseFloat(targetPrice) * parseFloat(Qty_Val);
totalPrice=totalPrice.toFixed(targetNumbersPoint);
var priceFormat=WPT_DATA.priceFormat;
totalPrice=totalPrice.replace('.', targetPriceDecimalSeparator);
var newPrice;
switch (priceFormat){
case 'left':
newPrice=targetCurrency+ (totalPrice + '').replace(/\B(?=(?:\d{3})+\b)/g, targetPriceThousandlSeparator);
break;
case 'right':
newPrice=(totalPrice + '').replace(/\B(?=(?:\d{3})+\b)/g, targetPriceThousandlSeparator) + targetCurrency;
break;
case 'left-space':
newPrice=targetCurrency + ' ' +  (totalPrice + '').replace(/\B(?=(?:\d{3})+\b)/g, targetPriceThousandlSeparator);
break;
case 'right-space':
newPrice=(totalPrice + '').replace(/\B(?=(?:\d{3})+\b)/g, targetPriceThousandlSeparator) + ' ' + targetCurrency;
break;
}
$('.yith_request_temp_' + temp_number + '_id_' + product_id).attr('data-quantity', Qty_Val);
$('#table_id_' + temp_number + ' .product_id_' + product_id + ' .wpt_total_item.total_general strong').html(newPrice);
updateCheckBoxCount(temp_number);
}
upateGlobalCheckboxCount();
function upateGlobalCheckboxCount(){
var add_cart_text=$('.wpt-wrap').data('basic_settings').add_to_cart;
var currentAllSelectedButtonSelector=$('body a.wpt-global-added-to-cart>span');
var itemAmount=0;
var itemCountSystem=config_json.item_count;
$('.wpt-wrap input.enabled.wpt_tabel_checkbox:checked').each(function(){
var product_id=$(this).data('product_id');
var items=$('tr#product_id_' + product_id).attr('data-quantity');
items=parseFloat(items);
if(items <=0){
return;
}
if(typeof itemCountSystem!=='undefined'&&itemCountSystem==='all'){
itemAmount +=items;
}else{
itemAmount++;
}});
var checkBoxWrapper=$('a.wpt-global-added-to-cart');
if(itemAmount > 0){
checkBoxWrapper.fadeIn();
checkBoxWrapper.removeClass('wpt-added-to-cart-empty');
}else{
checkBoxWrapper.fadeOut();
checkBoxWrapper.addClass('wpt-added-to-cart-empty');
}
var itemText=config_json.items;//'Items';
if(itemAmount===1||itemAmount===0){
itemText=config_json.item;//'Item';
}
if(itemAmount > 0||currentAllSelectedButtonSelector.hasClass('already_counted')){
currentAllSelectedButtonSelector.addClass('already_counted');
currentAllSelectedButtonSelector.html(add_cart_text + ' [ ' + itemAmount + ' ' + itemText + ' ]');
}}
function updateCheckBoxCount(temp_number){
upateGlobalCheckboxCount();
config_json=getConfig_json(temp_number);
var add_cart_text=$('#table_id_' + temp_number).data('basic_settings').add_to_cart;
var currentAllSelectedButtonSelector=$('#table_id_' + temp_number + ' a.button.add_to_cart_all_selected');
var itemAmount=0;
var itemCountSystem=config_json.item_count;
$('table.wpt_temporary_table_' + temp_number + ' .wpt-tr-tag.wpt_row').removeClass('wpt_selected_tr');
$('#table_id_' + temp_number + ' input.enabled.wpt_tabel_checkbox:checked').each(function(){
var product_id=$(this).data('product_id');
$('table.wpt_temporary_table_' + temp_number + ' .wpt-tr-tag.wpt_row#product_id_' + product_id).addClass('wpt_selected_tr');
var items=$('#table_id_' + temp_number + ' tr#product_id_' + product_id).attr('data-quantity');
items=parseFloat(items);
if(items <=0){
return;
}
if(typeof itemCountSystem!=='undefined'&&itemCountSystem==='all'){
itemAmount +=items;
}else{
itemAmount++;
}});
var checkBoxWrapper=$('#table_id_' + temp_number + ' .all_check_header_footer');
if(itemAmount > 0){
checkBoxWrapper.addClass('product-selected');
}else{
checkBoxWrapper.removeClass('product-selected');
}
var itemText=config_json.items;//'Items';
if(itemAmount===1||itemAmount===0){
itemText=config_json.item;//'Item';
}
if(itemAmount > 0||currentAllSelectedButtonSelector.hasClass('already_counted')){
currentAllSelectedButtonSelector.addClass('already_counted');
currentAllSelectedButtonSelector.html(add_cart_text + ' [ ' + itemAmount + ' ' + itemText + ' ]');
}
var argStats={};
argStats['temp_number']=temp_number;
argStats['table_id']=temp_number;
argStats['itemAmount']=itemAmount;
argStats['itemText']=itemText;
argStats['button_text']=add_cart_text;
argStats['button_object']=currentAllSelectedButtonSelector;
$(document.body).trigger('wpt_count_updated',argStats);
}
$(document.body).on('updateCheckBoxCount',function(temp_number){
updateCheckBoxCount(temp_number);
});
$('body').on('click', 'input.wpt_check_universal,input.enabled.wpt_tabel_checkbox.wpt_td_checkbox', function(){
var temp_number=$(this).data('temp_number');
var checkbox_type=$(this).data('type');
if(checkbox_type==='universal_checkbox'){
$('#table_id_' + temp_number + ' input.enabled.wpt_tabel_checkbox.wpt_td_checkbox:visible').prop('checked', this.checked);
$('input#wpt_check_uncheck_column_' + temp_number).prop('checked', this.checked);
$('input#wpt_check_uncheck_button_' + temp_number).prop('checked', this.checked);
}
var temp_number=$(this).data('temp_number');
updateCheckBoxCount(temp_number);
});
function uncheckAllCheck(temp_number){
var selectedCheckBox=$('#table_id_' + temp_number + ' .all_check_header input[type=checkbox],#table_id_' + temp_number + ' .wpt_table_tag_wrapper input[type=checkbox]');
selectedCheckBox.each(function(){
if($(this).is(':checked')){
$(this).trigger('click');
}});
updateCheckBoxCount(temp_number);
}
$('.instance_search_input').keyup(function (){
var text, value_size, serial;
var temp=$(this).data('temp_number');
var value=$(this).val();
value=value.trim();
value=value.split(' ');
value=value.filter(function (eachItem){
return eachItem!=='';
});
value_size=value.length;
var target_table='#table_id_' + temp + ' #wpt_table';
$(target_table + ' .wpt-tr-tag.visible_row').each(function (){
text=$(this).text();
text=text.replace(/[\u200B-\u200D\uFEFF]/g, '');
text=text.toLowerCase();
serial=0;
value.forEach(function (eachItem){
if(eachItem.length===1){
if(text.match(new RegExp('\\b' + eachItem, 'i'))){
serial++;
}}else{
if(text.match(new RegExp(eachItem, 'i'))){
serial++;
}}
});
if(serial===value_size){
$(this).fadeIn(100);
$(this).addClass('instance_search_applied');
}else{
$(this).fadeOut(100);
$(this).removeClass('instance_search_applied');
}});
});
function emptyInstanceSearchBox(temp_number){
$('#table_id_' + temp_number + ' .instance_search_input').val('');
}
$(window).on('wpt_changed_variations',function(e,Attrs){
if(Attrs.status){
var product_id=Attrs.product_id;
var quoteElm=$('.wpt-tr-tag.product_id_'+product_id + ' .wpt-td-tag.wpt_quoterequest a.wpt_yith_add_to_quote_request');
try{
var response_msg=quoteElm.data('msg');
quoteElm.html(response_msg.text);
quoteElm.closest('div.quoterequest').find('.yith_ywraq_add_item_response_message').remove();
quoteElm.closest('div.quoterequest').find('.yith_browse_link').remove();
}catch(e){
}}
});
$('body').on('click','a.wpt_yith_add_to_quote_request.enabled',function(e){
e.preventDefault();
var thisButton=$(this);
if(typeof ywraq_frontend==='undefined'){
alert("Quote Request plugin is not installed.");
return false;
}
var msg=$(this).data('msg');
var response_msg=$(this).attr('data-response_msg');
var type=$(this).closest('.wpt-tr-tag.wpt_row').data('type')
if(type!=='variable'&&response_msg!==''){
showAlert(response_msg);
$('.' + selector).html(msg.added);
return false;
}
var selector=$(this).data('selector');
$('.' + selector).html(msg.adding);
var add_to_cart_info;
var wp_nonce=$(this).data('wp_nonce');
var product_id=$(this).data('product_id');
var parent_id=$(this).closest('.wpt-tr-tag.wpt_row').data('parent_id');
var quantity=$(this).attr('data-quantity');
var quote_data=$(this).attr('data-quote_data');
var yith_browse_list=$(this).data('yith_browse_list');
var temp_number=$(this).closest('.wpt-tr-tag.wpt_row').data('temp_number');
var addToCartSelector=$('#table_id_' + temp_number + ' #product_id_' + product_id + ' a.wpt_product_title_in_td');
var tableRow=$('#table_id_' + temp_number + ' #product_id_' + product_id);
var url_params=tableRow.attr('data-href');
var split_params=url_params.split('?');
if(typeof split_params[1]!=='undefined'&&type==='variation'){
quote_data='&' + split_params[1];
}
add_to_cart_info='action=yith_ywraq_action&ywraq_action=add_item&quantity=' + quantity + '&product_id='+ product_id +'&_wpnonce='+ywraq_frontend.yith_ywraq_action_nonce;
add_to_cart_info +=quote_data;
if(type==='variation'){
var variation_id=product_id;
product_id=parent_id;
add_to_cart_info +='&variation_id=' + variation_id;
}
var yith_ajax_url;
yith_ajax_url=ywraq_frontend.ajaxurl.toString().replace('%%endpoint%%', 'yith_ywraq_action');
$.ajax({
type:'POST',
url:ywraq_frontend.ajaxurl,
dataType: 'json',
data:add_to_cart_info,
beforeSend: function(){
},
complete: function(){
},
success: function (response){
if(response&&(response.result==='true'||response.result==='exists') ){
$('.' + selector).html(msg.added);
$('.' + selector).attr('data-response_msg',response.message);
var html;
html='<div class="yith_ywraq_add_item_response_message">' + response.message + '</div>';
html +='<a class="yith_browse_link" href="'+response.rqa_url+'" target="_blank">' + yith_browse_list + '</a>';
$('.' + selector).parent().append(html).show(); //response.label_browse
}else{
$('.' + selector).html(msg.added);
}}
});
});
loadMiniFilter();
$(document.body).on('wpt_ajax_loaded',function(){
loadMiniFilter();
});
function loadMiniFilter(){
$('.wpt-wrap .wpt-mini-filter select.filter_select').each(function(){
var id=$(this).attr('id');
var temp_number=$(this).data('temp_number');
var config_json=getConfig_json(temp_number);
var key=$(this).data('key');
var label=$(this).data('label');
var taxArray=new Array();
var taxValArray=new Array();
taxArray.sort();
$('#table_id_' + temp_number + ' .wpt-tbody-tag .wpt-tr-tag').each(function(){
var tax=$(this).data(key);
if(tax&&tax!==''){
tax=tax.replace(/,\s*$/, "");
tax=tax.replace(/\s/g, ' ');
tax=tax.split(',');
tax.forEach(function(item){
item=item.trimStart(" ");
var taxDetails=item.split(':');
var taxID=taxDetails[0];
var taxValue=taxDetails[1];
taxArray[taxID]=taxValue;
taxValArray[taxValue]=taxID;
});
}});
if(config_json.sort_mini_filter==='ASC'){
taxArray.sort();
}else if(config_json.sort_mini_filter==='DESC'){
taxArray.sort();
taxArray.reverse();
}
var html='<option value="">' + label + '</option>';
taxArray.forEach(function(value,number){
html +='<option value="' + key + '_' + temp_number + '_' + taxValArray[value] + '">' + value + '</option>';
});
$(this).html(html);
});
}
function textToIntForSorting(text){
text=text.replace(/[^0-9.]/g,'');
text=parseFloat(text);
if(text==''){
text=0;
}
text=text * 100000;
text=parseInt(text);
return text;
}
$(document.body).on('click','div.wpt_column_sort .wpt-table-tag.wpt_product_table .wpt-thead-tag .wpt-tr-tag .wpt-th-tag',function(){
var unq_id=$(this).closest('div.wpt-wrap').data('unique_id');
var class_for_sorted='this_column_sorted';
var temp_number=$(this).parent().data('temp_number');
var target_class='.' + $(this).data('target_class');
var target_table_wrapper_id="div#table_id_" + temp_number + "[data-unique_id='" + unq_id + "']";
var thisColObject=$(this);
var status=false;
var disableClass=[
'.wpt_quantity',
'.wpt_check',
];
var number_class=$('.wpt-td-tag'+target_class + '>.text_with_number');
var content_type='normal';
if(number_class.length > 0||target_class.search('.wpt_serial_number')!=-1||target_class.search('.wpt_product_id')!=-1||target_class.search('.wpt_total')!=-1){
content_type='number';
}else if(target_class.search('.wpt_price')!=-1){
content_type='price';
}
var sort_type=$(this).attr('data-sort_type');
if(!sort_type||sort_type==='ASC'){
sort_type='ASC';
$(this).attr('data-sort_type','DESC');
}else{
$(this).attr('data-sort_type','ASC');
}
var audioItems=$(target_table_wrapper_id).find('.mejs-container');
if(audioItems.length > 0){
return;
}
if($.inArray(target_class,disableClass)==-1){
$(target_table_wrapper_id + ' .' +class_for_sorted).removeClass(class_for_sorted);
target_class='.' + $(this).data('target_class');
var contentHTMLArray=[];
var currentColumnObject=$(target_table_wrapper_id + ' .wpt-table-tag .wpt-tbody-tag .wpt-td-tag' + target_class);
currentColumnObject.each(function(index){
var text,
html='',
product_id=$(this).parent('.wpt-tr-tag').data('product_id');
text=$(this).text();
text=$.trim(text);
if(content_type=='price'){
text=$(this).find('span.woocommerce-Price-amount.amount').last().text();
text=textToIntForSorting(text);
}else if(content_type=='number'){
text=textToIntForSorting(text);
}else{
text=$.trim(text.substring(0,80));
text=text + "_" + product_id;
}
var thisRowObject=$('#table_id_'+ temp_number +' #product_id_' + product_id);
html=thisRowObject.prop('outerHTML');
contentHTMLArray[index]={
product_id: product_id,
gen_val: text,
html: html
};});
function sortingData(prevData,nextData){
var a=prevData['gen_val'];
var b=nextData['gen_val'];
var return_data;
if(sort_type==='ASC'){
return_data=((a < b) ? -1:((a > b) ? 1:0));
}else{
return_data=((b < a) ? -1:((b > a) ? 1:0));
}
return return_data;
}
contentHTMLArray.sort(sortingData);
var finalHTMLData='';
$.each(contentHTMLArray,function(index,value){
finalHTMLData +=value.html;
});
$(target_table_wrapper_id + ' .wpt-table-tag > .wpt-tbody-tag').html(finalHTMLData);
$(target_table_wrapper_id + ' ' +target_class).addClass(class_for_sorted);
status=true;
}
var argStats={};
argStats['status']=status;
argStats['temp_number']=temp_number;
argStats['table_id']=temp_number;
argStats['this_object']=thisColObject;
$(document.body).trigger('wpt_column_sorted',argStats);
$(document.body).trigger('wpt_ajax_loaded');
});
removeCatTagLings();
$(document.body).on('wpt_ajax_loaded',removeCatTagLings);
function removeCatTagLings(){
if(config_json.disable_cat_tag_link==='1'){
$('.wpt_category a,.wpt_tags a,.wpt_custom_tax a').removeAttr("href");
}}
function Advance_NoticeBoard(response){
var noticeBoard=$('div.wpt_notice_board');
var eachNoticeInnter=$(response);
eachNoticeInnter.css('display','none');
if(response!==''){
noticeBoard.prepend(eachNoticeInnter);
eachNoticeInnter.fadeIn();
setTimeout(function(){
eachNoticeInnter.fadeOut();
eachNoticeInnter.remove();
},notice_timeout);
}}
function WPT_BlankNotice(){
var noticeBoard=$('div.wpt_notice_board');
noticeBoard.html('');
}
$(document).on('submit','div.advance_table_wrapper .wpt-table-tag.advance_table.wpt_product_table form',function(e){
footerCartAnimation();
WPT_BlankNotice();
var product_id=$(this).parents('.wpt-tr-tag').data('product_id');
var thisButton=$('tr#product_id_' + product_id + ' .wpt_action button.single_add_to_cart_button');
if(thisButton.hasClass('disabled')){
return;
}
var thisTable=$(this).parents('div.wpt-wrap');
var table_id=$(this).parents('div.wpt-wrap').attr('id');
var data_json=$(this).closest('.wpt-wrap').data('basic_settings');
var ajax_action=data_json.ajax_action;
var thisRow=$(this).closest('.wpt-tr-tag.wpt-row');
var messageBox=thisRow.find('input.wpt_custom_message');
var Bubble=thisRow.find('.wpt_ccount');
if(Bubble.length==0){
thisRow.find('.single_add_to_cart_button').append('<span class="wpt_ccount wpt_ccount_' + product_id + '"><i class="wpt-spin5 animate-spin"></span>');
}else{
Bubble.html('<i class="wpt-spin5 animate-spin">');
}
thisButton.removeClass('added');
thisButton.addClass('disabled');
var form=$(this);
var url=form.attr('action');
var method=form.attr('method');
if('post'===method&&ajax_action==='ajax_active'){
e.preventDefault();
}else{
return;
}
var checkoutURL=WPT_DATA.checkout_url;
var cartURL=WPT_DATA.cart_url;
$.post(url, form.serialize() + '&add-to-cart=' + product_id + '&_wp_http_referer=' + url, function(data,status,xh){ //form.serialize() + '&_wp_http_referer=' + url
thisTable.removeClass('loading');
var notice=$('.woocommerce-message,.woocommerce-error', data);
if(config_json.popup_notice==='1'||config_json.popup_notice=='no'){
Advance_NoticeBoard(notice);
}
thisButton.removeClass('disabled');
thisButton.addClass('added');
}).done(function(){
messageBox.val('');
$(document.body).trigger('updated_cart_totals');
$(document.body).trigger('wc_fragments_refreshed');
$(document.body).trigger('wc_fragments_refresh');
$(document.body).trigger('wc_fragment_refresh');
if(config_json.product_direct_checkout==='yes'){
window.location.href=checkoutURL;
return;
}
if(config_json.product_direct_checkout==='cart'){
window.location.href=cartURL;
return;
}
var argStats={};
argStats['status']=true;
argStats['product_id']=product_id;
argStats['form']=form;
argStats['url']=url;
argStats['temp_number']=table_id;
argStats['table_id']=table_id;
$(document.body).trigger('wpt_added_to_cart_advance',argStats);
});
});
$('div.advance_table_wrapper a.button.add_to_cart_all_selected').click(function(){
WPT_BlankNotice();
var temp_number=$(this).data('temp_number');
var allMessageBox=$('#table_id_' + temp_number + ' .wpt_custom_message');
var checkoutURL=WPT_DATA.checkout_url;//$('#table_id_' + temp_number).data('checkout_url');
var cartURL=WPT_DATA.cart_url;//$('#table_id_' + temp_number).data('cart_url');
var tableWrapperTag=$('#table_id_' + temp_number + ' .wpt_table_tag_wrapper');
tableWrapperTag.addClass('wpt-ajax-loading');
var currentAllSelectedButtonSelector=$('#table_id_' + temp_number + ' a.button.add_to_cart_all_selected');
currentAllSelectedButtonSelector.addClass('disabled');
currentAllSelectedButtonSelector.addClass('loading');
var add_cart_text=$('#table_id_' + temp_number).data('basic_settings').add_to_cart;
var itemAmount=0;
var products_data={};
$('#table_id_' + temp_number + ' input.enabled.wpt_tabel_checkbox.wpt_td_checkbox:checked').each(function(){
WPT_BlankNotice();
var product_id=$(this).data('product_id');
var fullSelcetor='#table_id_' + temp_number + ' #product_id_' + product_id + ' .wpt_action form';
var thisButton=$('#table_id_' + temp_number + ' #product_id_' + product_id + ' .wpt_action form button.single_add_to_cart_button');
var form=$(fullSelcetor);
var title=$(this).parents('.wpt-tr-tag').data('title');
var additional_json=$(this).parents('.wpt-tr-tag').attr('additional_json');
var url=form.attr('action');
let eachProductData='product_id=' + product_id + '&' + form.serialize();
var obj={};
eachProductData.replace(/([^=&]+)=([^&]*)/g, function(m, key, value){
obj[decodeURIComponent(key)]=decodeURIComponent(value);
});
if(additional_json!==''){
obj['additional_json']=additional_json;
}
products_data[product_id]=obj;
var items=$('#table_id_' + temp_number + ' tr#product_id_' + product_id).attr('data-quantity');
items=parseFloat(items);
if(items <=0){
return;
}
var itemCountSystem=config_json.item_count;
if(typeof itemCountSystem!=='undefined'&&itemCountSystem==='all'){
itemAmount +=items;
}else{
itemAmount++;
}});
if(itemAmount < 1){
currentAllSelectedButtonSelector.removeClass('disabled');
currentAllSelectedButtonSelector.removeClass('loading');
showAlert(config_json.please_choose_items);
return false;
}
uncheckAllCheck(temp_number);
currentAllSelectedButtonSelector.html(add_cart_text + ' [ ' + config_json.loading_more_text + ' ]');
$.ajax({
type: 'POST',
url: ajax_url,
data: {
action: 'wpt_ajax_mulitple_add_to_cart',
products: products_data,
},
complete: function(){
$(document).trigger('wc_fragments_refreshed');
},
success: function(response){
$(document.body).trigger('added_to_cart');
$(document.body).trigger('updated_cart_totals');
$(document.body).trigger('wc_fragments_refreshed');
$(document.body).trigger('wc_fragments_refresh');
$(document.body).trigger('wc_fragment_refresh');
currentAllSelectedButtonSelector.html(add_cart_text + ' [ ' + itemAmount + ' ' + config_json.add2cart_all_added_text + ' ]');
WPT_NoticeBoard();
if(config_json.all_selected_direct_checkout==='yes'){
window.location.href=checkoutURL;
return;
}else if(config_json.all_selected_direct_checkout==='cart'){
window.location.href=cartURL;
return;
}
currentAllSelectedButtonSelector.removeClass('disabled');
currentAllSelectedButtonSelector.removeClass('loading');
allMessageBox.val('');//3.2.5.5.final10
tableWrapperTag.removeClass('wpt-ajax-loading');
},
error: function(){
alert('Failed');
},
});
currentAllSelectedButtonSelector.removeClass('disabled');
currentAllSelectedButtonSelector.removeClass('loading');
$(document).trigger('wc_fragments_refreshed');
if(config_json.all_selected_direct_checkout==='yes'){
window.location.href=checkoutURL;
return;
}
if(config_json.product_direct_checkout==='cart'){
window.location.href=cartURL;
return;
}});
$(document.body).on('wpt_ajax_load_data',function(e,data){
var temp_number=data.table_id;
uncheckAllCheck(temp_number);
});
$(document).on('reset_data', 'div.advance_table_wrapper .wpt-table-tag.advance_table.wpt_product_table form.cart', function(){
var thisRow=$(this).parents('.wpt-tr-tag.wpt_row');
var temp_number=thisRow.data('temp_number');
var product_id=thisRow.data('product_id');
var quoted_target='yith_request_temp_' + temp_number + '_id_' + product_id;
var addToQuoteSelector=$('.' + quoted_target);
var checkBoxSelector=$('.wpt_check_temp_' + temp_number + '_pr_' + product_id);
thisRow.attr('data-variation_id', '');
function enable_disable_class(){
addToQuoteSelector.removeClass('enabled');
addToQuoteSelector.addClass('disabled');
checkBoxSelector.removeClass('enabled');
checkBoxSelector.addClass('disabled');
}
enable_disable_class();
var skuTDobj=$('#table_id_' + temp_number + ' #product_id_' + product_id + ' .td_or_cell.wpt_sku');
var sku=skuTDobj.data('sku');
skuTDobj.find('div.wpt_sku').html(sku);
});
$(document).on('found_variation', 'div.advance_table_wrapper .wpt-table-tag.advance_table.wpt_product_table form.cart', function(event, variation){
var thisRow=$(this).parents('.wpt-tr-tag.wpt_row');
var temp_number=thisRow.data('temp_number');
var product_id=thisRow.data('product_id');
var my_product_id=$(event.currentTarget).parents('.wpt-tr-tag.wpt_row').data('product_id');
var targetThumbs=$('#table_id_' + temp_number + ' #product_id_' + product_id + ' wpt_thumbnails img');
var quoted_target='yith_request_temp_' + temp_number + '_id_' + product_id;
var addToQuoteSelector=$('.' + quoted_target);
var checkBoxSelector=$('.wpt_check_temp_' + temp_number + '_pr_' + product_id);
function targetTD(td_name){
var targetElement=$('#table_id_' + temp_number + ' #product_id_' + product_id + ' wpt_' + td_name);
return targetElement;
}
var sku=variation.sku;
var skuTDobj=$('#table_id_' + temp_number + ' #product_id_' + product_id + ' div.wpt_sku');
skuTDobj.html(sku);
thisRow.attr('data-variation_id', variation.variation_id);
function setValueToTargetTD_IfAvailable(target_td_name, gotten_value){
if(gotten_value!==""){
targetTD(target_td_name).html(gotten_value);
}}
function setValueToTargetTD(target_td_name, gotten_value){
targetTD(target_td_name).html(gotten_value);
}
targetThumbs.attr('src', variation.image.gallery_thumbnail_src);
if(variation.image.srcset&&'false'!==variation.image.srcset){
targetThumbs.attr('srcset', variation.image.srcset);
};
function disbale_enable_class(){
addToQuoteSelector.removeClass('disabled');
addToQuoteSelector.addClass('enabled');
checkBoxSelector.removeClass('disabled');
checkBoxSelector.addClass('enabled');
}
disbale_enable_class();
targetThumbs.attr('data-variation_id', variation.variation_id);
});
$('.wpt-wrap').each(function(){
var table_id=$(this).data('temp_number');
var tableEl=$(this).find('.wpt-table-tag.wpt_product_table');
var width=tableEl.width();
$('.wpt_second_wrapper.wpt_second_wrapper_' + table_id + ' div.wpt_second_content').css('width',width);
});
$(".wpt_table_tag_wrapper").scroll(function (){
$(".wpt_second_wrapper").scrollLeft($(".wpt_table_tag_wrapper").scrollLeft());
});
$(".wpt_second_wrapper").scroll(function (){
$(".wpt_table_tag_wrapper").scrollLeft($(".wpt_second_wrapper").scrollLeft());
});
$('.wpt_product_table input.input-text.qty.text').trigger('change');
$('.yith-ywraq-add-to-quote').each(function(){
let qty=$(this).closest('.wpt-tr-tag').data('quantity');
$(this).append('<input type="hidden" class="input-text qty text" value="' + qty + '">');
});
});
});