I have added new custom shipping field ( select option ) to woocommerce checkout page.
I am using that for shipping calculations.
that works perfect as well. but issue is while I change values in that field it do not update instantly.
It gives correct calculations on next page, after page submit. I need it to work as change in custom field.
How to trigger WooCommerce Ajax which updates shipping calculation on change of my custom field ?
Go to WooCommerce > Settings > ACS Web Services. Check Enable ACS Automatic Shipping Calculation and press Save. On Weight you will be able to select Automatic Weight if you want to calculate the shipping fee based on order's total weight or select flat to set a fixed order weight.
Head to: WooCommerce > Settings > Shipping. Select the Shipping Zone that Flat Rate should be added to and select Edit. In the Shipping Methods box, select Add Shipping Method. Select Flat Rate shipping from the dropdown and then Add Shipping method.
This is actually extremely simple to do if you are adding your fields in the correct way(using the woocommerce_checkout_fields
filter). The only thing you need to do is to add the classes address-field
and update_totals_on_change
like this:
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With