Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- Estimate shipping values on the checkout page -->
- <script>
- function cleanEstimates(){
- // remove all prices and errors
- $('#shipping_options li').each(function(){ $(this).children().last().detach(); });
- // add empty messages - placeholders
- $('#shipping_options li').each(function(){ $(this).append('<span></span>') });
- }
- function shippingEstimates(){
- if($('#order_shipping_address_country').val() != "" && $('#order_shipping_address_region').val() != ""){
- $.ajax({
- method: "POST",
- url: "/checkout/shipping_estimate",
- data: {
- estimate: {
- country: $('#order_shipping_address_country').val(),
- region: $('#order_shipping_address_region').val(),
- municipality: $('#order_shipping_address_municipality').val(),
- postal: $('#order_shipping_address_postal') .val()
- }
- }
- }).done(function( data ) {
- for(var i = 0; i < data.length; i++){
- // remove any previous messages & placeholders
- $('#shipping_options #order_shipping_method_' + data[i].table.id).parent().children().last().detach();
- if(data[i].table.error){
- // disable options with errors
- $('#shipping_options #order_shipping_method_' + data[i].table.id).attr('disabled', 'disabled');
- // add error messages
- $('#shipping_options #order_shipping_method_' + data[i].table.id).parent().append("<p class='shipping_information'><i>" + data[i].table.error_message + "</i></p>")
- } else {
- // enable options
- $('#shipping_options #order_shipping_method_' + data[i].table.id).attr('disabled', false);
- // add formatted shipping prices
- $('#shipping_options #order_shipping_method_' + data[i].table.id).parent().append("<p class='shipping_information'><i>" + data[i].table.price + "</i></p>")
- }
- }
- });
- } else {
- // no Country or Region filled, clear shipping estimate info
- cleanEstimates();
- }
- }
- $('#order_shipping_address_country').change(function(){shippingEstimates()});
- $('#order_shipping_address_region').change(function(){shippingEstimates()});
- $('#order_shipping_address_municipality').change(function(){shippingEstimates()});
- $(document).ready(function(){
- // add empty messages - placeholders
- $('#shipping_options li').each(function(){ $(this).append('<span></span>') });
- shippingEstimates();
- })
- </script>
Add Comment
Please, Sign In to add comment