| @ -1,28 +1,66 @@ | |||||
| (function( $ ) { | (function( $ ) { | ||||
| 'use strict'; | 'use strict'; | ||||
| $(function() { | |||||
| $( document.body ).on( 'submit', '.woocommerce-shipping-calculator', function() { | |||||
| 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(); | |||||
| } | |||||
| }, | |||||
| var WC_Fvc = { | |||||
| /** | |||||
| * Initialize actions. | |||||
| */ | |||||
| init: function() { | |||||
| $( document.body ).on( 'submit', '.woocommerce-shipping-calculator', function(event) { | |||||
| event.preventDefault(); | |||||
| WC_Fvc.block(); | |||||
| 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(); | |||||
| } | |||||
| }, | |||||
| }); | |||||
| }); | |||||
| }, | |||||
| /** | |||||
| * Block shipping form. | |||||
| */ | |||||
| block: function() { | |||||
| $('.woocommerce-shipping-calculator, div.cart_totals') | |||||
| .addClass('processing') | |||||
| .block({ | |||||
| message: null, | |||||
| overlayCSS: { | |||||
| background: '#fff', | |||||
| opacity: 0.6, | |||||
| } | |||||
| }); | }); | ||||
| }); | |||||
| }, | |||||
| /** | |||||
| * Unblock checkout. | |||||
| */ | |||||
| unblock: function() { | |||||
| $('.woocommerce-shipping-calculator, div.cart_totals') | |||||
| .removeClass('processing') | |||||
| .unblock(); | |||||
| }, | |||||
| }; | |||||
| $(function() { | |||||
| WC_Fvc.init(); | |||||
| }); | }); | ||||
| })( jQuery ); | })( jQuery ); | ||||