' ; setTimeout(function(){ var default_selected_country = "United States"; $("#AddressCountryNew option[value='"+default_selected_country+"']").prop('selected', 'selected').change(); }, 1000); // var dateToday = new Date(); // var skip_today = "false"; // var skip_today_tomarrow = "false"; // if(skip_today == "true"){ // dateToday = new Date(dateToday.setDate(dateToday.getDate() + 1)); // } // if(skip_today_tomarrow == "true"){ // dateToday = new Date(dateToday.setDate(dateToday.getDate() + 2)); // } // var dates = $("#date_picker").datepicker({ // defaultDate: "+1w", // changeMonth: true, // numberOfMonths: 1, // minDate: dateToday, // onSelect: function(selectedDate) { // var option = this.id == "from" ? "minDate" : "maxDate", // instance = $(this).data("datepicker"), // date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings); // dates.not(this).datepicker("option", option, date); // } // }); var picker = new Pikaday( { field: document.getElementById('date_picker'), firstDay: 1, minDate: new Date(), maxDate: new Date(2020, 12, 31), yearRange: [2000,2020] }); $(".slct_cntry select").on('change', function(){ var state_data = $(this).find('option:selected').attr("data-provinces"); state_data = JSON.parse(state_data); if(state_data == ""){ // $(".slct_state select").empty().append('Select state'); $(".slct_state").hide(); }else{ $(".slct_state select").empty(); state_data.forEach(function(data, i){ var _option = ''+data[0]+''; $(".slct_state select").append(_option); }); $(".slct_state").show(); } }); // $(document).on('change','.slct_cntrybill select', function(){ // var state_data = $(this).find('option:selected').attr("data-provinces"); // state_data = JSON.parse(state_data); // if(state_data == ""){ // // $(".slct_state select").empty().append('Select state'); // $(".slct_statebill").hide(); // }else{ // $(".slct_statebill select").empty(); // state_data.forEach(function(data, i){ // var _option = ''+data[0]+''; // $(".slct_statebill select").append(_option); // }); // $(".slct_statebill").show(); // } // }); $('[name="billing_address_same_as_shipping_address"]').change(function(){ if($(this).is(":checked")){ $(".billingaddress").empty(); }else{ $(".billingaddress").append(billing_html); $(document).on('change','.slct_cntrybill select', function(){ var state_data = $(this).find('option:selected').attr("data-provinces"); state_data = JSON.parse(state_data); if(state_data == ""){ // $(".slct_state select").empty().append('Select state'); $(".slct_statebill").hide(); }else{ $(".slct_statebill select").empty(); state_data.forEach(function(data, i){ var _option = ''+data[0]+''; $(".slct_statebill select").append(_option); }); $(".slct_statebill").show(); } }); } }); $('.auto_address').on('change', function(){ var _val = $(this).val(); var _form = $(this).parents('form'); console.log(_form); _form.find('[name="waioaddress[first_name]"]').val(''); _form.find('[name="waioaddress[last_name]"]').val(''); _form.find('[name="waioaddress[company]"]').val(''); _form.find('[name="waioaddress[address1]"]').val(''); _form.find('[name="waioaddress[address2]"]').val(''); _form.find('[name="waioaddress[city]"]').val(''); _form.find('[name="waioaddress[zip]"]').val(''); _form.find('[name="waioaddress[phone]"]').val(''); _form.find('[name*="waioaddress[country]"]')[0].selectedIndex=0; if(_val === '') return; var corresponding_data = customer_addresses[_val]; console.log(corresponding_data); if(typeof corresponding_data !== "undefined"){ _form.find('[name="waioaddress[first_name]"]').val(corresponding_data.first_name); _form.find('[name="waioaddress[last_name]"]').val(corresponding_data.last_name); _form.find('[name="waioaddress[company]"]').val(corresponding_data.company); _form.find('[name="waioaddress[address1]"]').val(corresponding_data.address1); _form.find('[name="waioaddress[address2]"]').val(corresponding_data.address2); _form.find('[name="waioaddress[city]"]').val(corresponding_data.city); _form.find('[name="waioaddress[zip]"]').val(corresponding_data.zip); _form.find('[name="waioaddress[phone]"]').val(corresponding_data.phone); _form.find('[name*="waioaddress[country]"]').val(corresponding_data.country_name).trigger('change'); _form.find('[name*="waioaddress[provice]"]').val(corresponding_data.province).trigger('change'); } }); $('.waio__nt--form_wrapper form').on('submit', function(e){ e.preventDefault(); var _form = $(this); var _po = ''; if(show_payment_mode) _po =_form.find('[name="payment"]').val(); else _po = default_payment_option; var _dd = ''; if(show_delivery_date) _dd =_form.find('[name="delivery_date"]').val(); var additional_info={}; // var _formArray = _form.serializeArray(); // _formArray.forEach(function(_address, i){ // if(_address.name.indexOf('waioaddress') != -1){ // var _d = _address.name.split('waioaddress')[1].replace('[', '').replace(']',''); // additional_info[_d] = _address.value; // } // }) additional_info["shipping_notes"] = _form.find('[name="shipping_notes"]').val(); additional_info["customer_tag"] = waioTranslations.tagss; var shipping_price =$("#wrapper-response").text().trim(); var _shipping_charges = true; if(shipping_price.indexOf("Rates start at") > -1){ var _price = shipping_price.replace("Rates start at $","").replace(" USD",""); var _title = "Shipping charges"; _shipping_charges = false; } console.log("_shipping_charges",_shipping_charges); console.log("_price",'"'+_price+'"'); console.log("_title",'"'+_title+'"'); var country = $("#AddressCountryNew").find("option:selected").val(); var province = $(".slct_state select").find("option:selected").val(); if($('[name="billing_address_same_as_shipping_address"]').is(":checked")){ additional_info["Billing_Address"] = "same as shipping"; }else{ additional_info["first_name"] = $(".billingaddress").find('[name="waiobilladdress[first_name]"]').val(); additional_info["last_name"] = $(".billingaddress").find('[name="waiobilladdress[last_name]"]').val(); additional_info["address1"] = $(".billingaddress").find('[name="waiobilladdress[address1]"]').val(); additional_info["address2"] = $(".billingaddress").find('[name="waiobilladdress[address2]"]').val(); additional_info["city"] = $(".billingaddress").find('[name="waiobilladdress[city]"]').val(); additional_info["company"] = $(".billingaddress").find('[name="waiobilladdress[company]"]').val(); additional_info["country"] = $(".billingaddress").find('[name="waiobilladdress[country]"]').val(); additional_info["phone"] = $(".billingaddress").find('[name="waiobilladdress[phone]"]').val(); additional_info["provice"] = $(".billingaddress").find('[name="waiobilladdress[provice]"]').val(); additional_info["zip"] = $(".billingaddress").find('[name="waiobilladdress[zip]"]').val(); } var _data = { "shop": "rinea.myshopify.com", "cart": cart, "customer_id": customer_id, "payment_option": _po, "delivery_date": _dd, "customer_tags": customer_tags, "additional_info": additional_info, "shipping_address": { "address1": _form.find('[name="waioaddress[address1]"]').val(), "address2": _form.find('[name="waioaddress[address2]"]').val(), "city": _form.find('[name="waioaddress[city]"]').val(), "company": _form.find('[name="waioaddress[company]"]').val(), "country": country, "first_name": _form.find('[name="waioaddress[first_name]"]').val(), "last_name": _form.find('[name="waioaddress[last_name]"]').val(), "latitude": "", "longitude": "", "phone": _form.find('[name="waioaddress[phone]"]').val(), "province": province, "zip": _form.find('[name="waioaddress[zip]"]').val(), "name": "", "country_code": "", "province_code": "" }, "app_shipping_charges": _shipping_charges, "shipping_charges": { "price": _price, "title": _title } }; console.log(_data); $.ajax({ type: 'POST', url: app_url+'/api/223/net-term', cache: false, data: _data, success: function(result){ if(result&&result.status==1){ // $(".waio__nt--form_wrapper").append("