Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce: Update shipping costs on checkout using ajax
<script type="text/javascript">
/* in order to update info on your checkout page you need to trigger update_checkout function
so add this in your javascript file for your theme or plugin
*/
jQuery('body').trigger('update_checkout');
/* what this does is update the order review table but what it doesn't do is update shipping costs;
the calculate_shipping function of your shipping class will not be called again;
so if you were like me and you made a shipping method plugin and you had to change costs based on payment method then
this is the only way to ensure it does just that
*/
</script>
<?php
# add this in your plugin file and that's it, the calculate_shipping method of your shipping plugin class will be called again
function action_woocommerce_checkout_update_order_review($array, $int)
{
WC()->cart->calculate_shipping();
return;
}
add_action('woocommerce_checkout_update_order_review', 'action_woocommerce_checkout_update_order_review', 10, 2);
?>
@CaroRed

This comment has been minimized.

Copy link

CaroRed commented Sep 16, 2017

Thank you. This is just what I needed... You helped me a lot.

@akshuvo

This comment has been minimized.

Copy link

akshuvo commented Oct 15, 2018

Great Great Great (y)

@parthtechcompose

This comment has been minimized.

Copy link

parthtechcompose commented Oct 31, 2018

Not working!

@aliyaghouti

This comment has been minimized.

Copy link

aliyaghouti commented May 7, 2020

not working for me :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.