Reputation: 397
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 ?
Upvotes: 7
Views: 11537
Reputation: 2882
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;
}
Upvotes: 12