How to update delivery calculations when changing a custom delivery field in woocommerce?

I added a new custom delivery field (select option) to the woocommerce verification page.

I use this for shipping calculations.

which works great. but the problem is that I am changing values ​​in this field that are not updated instantly.

It gives the correct calculations on the next page after the page is submitted. I need it to work as a custom field change.

How to run WooCommerce Ajax, which updates the delivery calculation when my custom field changes?

+5
source share
1 answer

This is very easy to do if you add the fields correctly (using the woocommerce_checkout_fields filter). The only thing you need to do is add the address-field and update_totals_on_change as follows:

 add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' ); function custom_override_checkout_fields( $fields ) { $fields['shipping']['custom_field'] = array( 'label' => 'Custom field', 'required' => 1, 'class' => array ('address-field', 'update_totals_on_change' ) ); return $fields; } 
+9
source

Source: https://habr.com/ru/post/1201979/


All Articles