Woocommerce checkout: Update cost OR update total price via “update_checkout” ajax event

So, i trigger update_checkout via javascript. Then, i have function to be called in woocommerce_review_order_before_shipping hook. The function is to add/remove free_shipping shipping method (it’s based on Cash on Delivery availability).

There are two radio buttons of payment method:

Read More
  • Direct Transfer
  • Cash on Delivery

The script already works. So when i choose COD (Cash on Delivery), the free shipping method is selected automatically.

But, the problem is the total price did not changed, this indicates that the cost is still available. Well, it changed, but it is late. I said late because the total price is canged when i change the payment method by choosing Direct Bank Transfer radio button.

The question is,

  1. why the total price doesn’t update realtime when the payment method is changed? Ok, it changed but in the next change event.
  2. what is WooCommerce API to update the total price OR to update the cost? Where in the hook should i place this?

🙂 Thank you very much for answering

Related posts

2 comments

  1. Have you tried this function in WC_AJAX:

    public static function update_order_review(){
    }
    

    By calling:

    WC_AJAX::checkout();
    
  2. Those two functions from WC API should help.

    calculate_totals() and calculate_shipping().

    global $woocommerce;
    
    $woocommerce->cart->calculate_totals();
    $woocommerce->cart->calculate_shipping();
    

Comments are closed.