Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function open_remodal() {
- var inst = jQuery('[data-remodal-id=modal]').remodal();
- /**
- * Opens the modal window
- */
- inst.open();
- }
- jQuery(document).ready(
- function() {
- var var1;
- var var2;
- /*
- * This is the VAT variable. Please edit this in case this changes after Brexit.
- */
- var vat = 0.2;
- var new_design_price = 30;
- recalculateTotals = function() {
- console.log("Var1: "+parseFloat(jQuery('.var1').val()));
- console.log("Var2: "+parseFloat(jQuery('.var2').val()));
- console.log("Var3: "+parseFloat(jQuery('.var3').val()));
- console.log("Var31: "+parseFloat(jQuery('.var31').val()));
- console.log("Var4: "+parseFloat(jQuery('.var4').val()));
- var total = (parseFloat(jQuery('.var2').val())+parseFloat(jQuery('.var3').val())+parseFloat(jQuery('.var31').val())+(parseFloat(jQuery('.var4').val())*parseFloat(jQuery('.var1').val()))).toFixed(2);
- var total_artwork_fee = (parseFloat(jQuery('.var3').val())+parseFloat(jQuery('.var31').val())).toFixed(2);
- var total_customisations = (parseFloat(jQuery('.var4').val())*parseFloat(jQuery('.var1').val())).toFixed(2);
- console.log("Total: "+total);
- jQuery('.totals').val(total);
- jQuery('.ginput_baseprice').html('£ '+(parseFloat(jQuery('.var2').val()).toFixed(2)));
- jQuery('.ginput_artworkfee').html('£ '+total_artwork_fee);
- jQuery('.ginput_customisationsprice').html('£ '+total_customisations);
- jQuery('.ginput_total').html('£ '+total);
- }
- sumjq = function(selector) {
- var sum = 0;
- jQuery(selector).each(function() {
- sum += Number(jQuery(this).val());
- });
- return sum;
- }
- getbulkprice = function(var1) {
- i=0;
- position=0;
- jQuery('.rp_wcdpd_pricing_table_quantity').each(
- function() {
- i++;
- buffer = jQuery(this).html();
- output = buffer.split("-");
- min = Number(output[0]);
- max = Number(output[1]);
- if(i==1)
- max=min;
- if(min <= var1 && max >= var1){
- position = i;
- }
- if(jQuery('.rp_wcdpd_pricing_table_quantity').length == i){
- min = Number(buffer.replace("+",""));
- max = Number(buffer.replace("+",""));
- }
- if(jQuery('.rp_wcdpd_pricing_table_quantity').length == i && var1 > max){
- position = i;
- }
- //console.log("min: "+min);
- //console.log("max: "+max);
- //console.log("i: "+i);
- }
- );
- return Number(jQuery('.woocommerce-Price-amount').eq(position+1).html().replace('<span class="woocommerce-Price-currencySymbol">£</span>',''));
- }
- jQuery('.qty_input').change(
- function() {
- var1 = sumjq('.qty_input');
- var2 = var1*getbulkprice(var1);
- jQuery('.var1').val(var1);
- jQuery('.var2').val(var2);
- //console.log('var1: '+var1);
- //console.log('var2: '+var2);
- calculateVar4();
- recalculateTotals();
- }
- );
- jQuery('#gchoice_10_38_0, #gchoice_10_38_1, #choice_10_33_0, #choice_10_33_1, #choice_10_39_0, #choice_10_39_1').click(
- function() {
- if(jQuery('#choice_10_33_0').is(':checked')){
- //jQuery('#var3').val(new_design_price);
- //console.log('var3: '+new_design_price);
- jQuery('.var3').val(parseFloat(new_design_price));
- recalculateTotals();
- } else {
- //jQuery('#var3').val(0);
- //console.log('var3: 0');
- jQuery('.var3').val(0);
- recalculateTotals();
- }
- }
- );
- jQuery('#gchoice_10_40_0, #gchoice_10_40_1, #choice_10_43_0, #choice_10_43_1, #choice_10_42_0, #choice_10_42_1').click(
- function() {
- if(jQuery('#choice_10_43_0').is(':checked')){
- //jQuery('#var31').val(new_design_price);
- //console.log('var31: '+new_design_price);
- jQuery('.var31').val(parseFloat(new_design_price));
- recalculateTotals();
- } else {
- //jQuery('#var31').val(0);
- //console.log('var31: 0');
- jQuery('.var31').val(0);
- recalculateTotals();
- }
- }
- );
- var step = 1;
- function calculateVar4() {
- if(step === 0){
- step = 1;
- } else {
- step = 0;
- var var4 = 0;
- var buffer = [];
- console.log(jQuery('.gfield_checkbox li.image-choices-choice-selected').length);
- if(jQuery('.gfield_checkbox li.image-choices-choice-selected').length === 0){
- jQuery('.var4').val(var4);
- recalculateTotals();
- }
- jQuery('.gfield_checkbox li.image-choices-choice-selected').each(function() {
- var classList = jQuery(this).attr('class').split(/\s+/);
- console.log(classList);
- if(buffer.indexOf(classList[0]) === -1){
- buffer.push(classList[0]);
- console.log(classList);
- //var classList = jQuery(this).attr('class').split(/\s+/);
- jQuery.each(classList, function(index, item) {
- if (Number(item.indexOf("gchoice")) === 0 && index === 0) {
- //console.log(product_title = jQuery('#choice_'+item.replace("gchoice_","")).val());
- var product_title = jQuery('#choice_'+item.replace("gchoice_","")).val();
- if(product_title !== null){
- var request = jQuery.ajax({
- url: "/wp-json/wooaddons/v1/discountprice/"+product_title+"/"+jQuery('.var1').val(),
- method: "GET",
- dataType: "json"
- });
- request.done(function( msg ) {
- console.log(msg);
- if(!isNaN(msg)){
- var4 = var4+(vat*parseFloat(msg))+parseFloat(msg);
- //console.log("var4: "+var4);
- jQuery('.var4').val(var4);
- recalculateTotals();
- }
- });
- request.fail(function( jqXHR, textStatus ) {
- console.log( "Request failed: " + textStatus );
- });
- }
- }
- });
- }
- });
- return var4;
- }
- }
- jQuery('ul.gfield_checkbox li.image-choices-choice').click( function() { calculateVar4(); } );
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment