WordPress WooCommerce中的javascript可以禁用运费计算吗?
这是我正在使用的代码和网站截图。因为在第三个或最后一个单选按钮是“Pick-up”,它只应删除从WooCommerce / WordPress传入的运费的计算。
有没有人有这个好的解决方案?谢谢!
$('#shipToCheckout').click(function() {
var radioValue = $("input[name='check-ship']:checked"). val();
var default_id = $(this).attr('rel');
var new_id = parseInt(default_id)+1;
if(radioValue == ""){
$(".paymentoption").html('');
$(".paymentoption").html('enter or select address');
}
var errMsg = '';
if(radioValue == '1'){
$("#pickup_date_time").hide();
$("tr.shipping").show();
$(".paymentoption").html('');
$(".paymentoption").html('You Selected - Enter shipping address');
var firstName = $("#firstName").val();
var lastName = $("#lastName").val();
var phoneUser = $("#phoneUser").val();
var floorUnit = $("#floorUnit").val();
var bldgName = $("#bldgName").val();
var cityList = $("#cityList option:selected").text();
var zipCode = $("#zipCode").val();
var landRemark = $("#remarkslandinput").val();
var saveResidence = $("input[name='saveResidence']:checked").val();
var residenceName = $("#residenceName").val();
if(floorUnit == "")
{errMsg = "* Floor Unit or House No. cannot be left blank!"+'\n';}
if(bldgName == "")
{errMsg += "* Bldg Name or House.cannot be left blank!"+'\n';}
if(zipCode == ""){errMsg += "* Zipcode cannot be left blank!"+'\n';}
if(saveResidence == "formcheck"){
if(residenceName == ""){errMsg += "* Residence Name cannot be left blank!";}}
if(errMsg){alert(errMsg);
return false;
}else{
if(saveResidence == "formcheck"){
$.post(WCMA_Ajax.ajaxurl, {
action : 'saveNewAddress',
id : new_id,
firstName : firstName,
lastName : lastName,
floorUnit : floorUnit,
bldgName : bldgName,
cityList : cityList,
zipCode : zipCode,
landRemark : landRemark,
residenceName : residenceName,
wc_multiple_addresses: WCMA_Ajax.wc_multiple_addresses
}, function (response) {
//alert(response);
}
);
}
var remarksdata = $('#remarkslandinput').val();
var floorUnit =$('#floorUnit').val();
var bldgName =$('#bldgName').val();
var cityList =$('#cityList').val();
var zipCode =$('#zipCode').val();
$('.ui.sidebar-shipto').sidebar('hide');
$('.ui.sidebar-checkout').sidebar('setting', 'transition', 'push');
$('.ui.sidebar-checkout').sidebar('push page');
$('.woocommerce-shipping-fields .shipping_address').show();
$("#shipping_first_name").val(firstName);
$("#shipping_last_name").val(lastName);
$('#shipping_address_1').val(floorUnit);
$('#shipping_address_2').val(bldgName);
$('#landmarkremarks-span').html(remarksdata);
$('#landmarkremarks').val(remarksdata);
$('#shipping_postcode').val(zipCode);
$('#shipping_postcode-span').html(zipCode);
$('#shipping_city-span').html(cityList);
$('#shipping_city').val(cityList);
$("#text-flrnumber").html(floorUnit);
$("#text-addressname").html(bldgName);
$("#text-cityaddress").html(cityList);
$("#text-postalid").html(zipCode);
$("#billing_phone").val(phoneUser);
$("#text-pickdate").html('');
$("#text-picktime").html('');
}
}else if(radioValue == '2'){
$("#pickup_date_time").show();
$(".paymentoption").html('');
$(".paymentoption").html('You Selected - Pick up from the store');
pickDate = $('#pick_date').val();
if(pickDate == ""){
//alert("please select date");
$("#pick_date").after("");
alert("Please select date.");
return false;
}else{
$('.ui.sidebar-shipto').sidebar('hide');
$('.ui.sidebar-checkout').sidebar('setting', 'transition', 'push');
$('.ui.sidebar-checkout').sidebar('push page');
pickTime = $('#pick_time').val();
html = '<div id="pickup_date_time">'+
'<b>Pickup Date: '+pickDate+'<br />Pickup Time: '+pickTime+'</b>'+
'<input type="hidden" name="h_pick_date" id="h_pick_date" value="'+pickDate+'" />'+
'<input type="hidden" name="h_pick_time" id="h_pick_time" value="'+pickTime+'" />'+
'</div>';
var firstName = $("#firstName").val();
var lastName = $("#lastName").val();
$( "#pickup_date_time" ).remove();
$('.woocommerce-shipping-fields').append(html);
$("#shipping_first_name").val(firstName);
$("#shipping_last_name").val(lastName);
$('#shipping_address_1').val('Pickup from Store');
$('#shipping_address_2').val('Pickup from Store');
$('#shipping_postcode').val('00000');
$('#landmarkremarks').html('landmarkremarks');
$("#text-flrnumber").html('');
$("#text-addressname").html('');
$("#text-cityaddress").html('');
$("#text-postalid").html('For Pickup');
$("#text-pickdate").html(pickDate);
$("#text-picktime").html(pickTime);
$("#order_comments").html('Pickup Date: '+pickDate+' Pickup Time: '+pickTime+'');
}
$("tr.shipping").hide();
}else if(radioValue == 'check'){
console.log('check');
var noSaved = $("input[name='no-saved-address']:checked").val();
if(noSaved == "nosaved"){
alert("You have no address saved yet, edit your profile to My Account sidebar.");
return false;
} else {
$('.ui.sidebar-shipto').sidebar('hide');
$('.ui.sidebar-checkout').sidebar('setting', 'transition', 'push');
$('.ui.sidebar-checkout').sidebar('push page');
$('.woocommerce-shipping-fields .shipping_address').show();
jQuery('input[name*=shipping_alt]').each(function(index){
if(jQuery(this).attr('checked')=='checked'){
firstName = $("#firstName").val();
lastName = $("#lastName").val();
address1 = jQuery('#address1',jQuery(this).parent()).html();
address2 = jQuery('#address2',jQuery(this).parent()).html();
city = jQuery('#city',jQuery(this).parent()).html();
var finalcity = city+' City';
console.log("city__"+finalcity);
postcode = jQuery('#postcode',jQuery(this).parent()).html();
$('#shipping_first_name').val(firstName);
$('#shipping_last_name').val(lastName);
$('#shipping_address_1').val(address1);
$('#shipping_address_2').val(address2);
$("#text-flrnumber").html(address1);
$("#text-addressname").html(address2);
$("#text-pickdate").html('');
$("#text-picktime").html('');
var myOptions = {'Makati City' : 'Makati City', 'Taguig City' : 'Taguig City'};
var mySelect = $('#shipping_city');
$.each(myOptions, function(val, text) {
mySelect.append($('<option></option>').val(val).html(text));
});
$('#shipping_city').val(finalcity);
$("#text-cityaddress").html(finalcity);
$('#shipping_postcode').val(postcode);
$("#text-postalid").html(postcode);
}
});
}
}
else{
$(".paymentoption").html('');
$(".paymentoption").html('enter or select address');
alert('Please select a shipping method.');
return false;
}
});