Plugin do WooCommerce para estimativa de frete usando somente o CEP.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
1.3 KiB

(function( $ ) {
'use strict';
var WC_Fvc = {
/**
* Initialize actions.
*/
init: function() {
$( document.body ).on( 'submit', 'form.woocommerce-shipping-calculator', function(event) {
event.preventDefault();
WC_Fvc.block('form.woocommerce-shipping-calculator, div.cart_totals');
var cep = $('#calc_shipping_postcode').val();
$.ajax({
type: 'GET',
url: wc_ajax_url,
async: false,
data: {
'wc-ajax': 'correios_autofill_address',
'postcode': cep,
},
dataType: 'json',
contentType: 'application/json',
success: function( address ) {
if ( address.success ) {
$('#calc_shipping_state').val(address.data.state).change();
$('#calc_shipping_city').val(address.data.city).change();
}
WC_Fvc.unblock('form.woocommerce-shipping-calculator, div.cart_totals');
},
});
});
},
/**
* Block shipping form.
*/
block: function(elements) {
$(elements)
.addClass('processing')
.block({
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6,
}
});
},
/**
* Unblock checkout.
*/
unblock: function(elements) {
$(elements)
.removeClass('processing')
.unblock();
},
};
$(function() {
WC_Fvc.init();
});
})( jQuery );