0

I need to add/update shipping cost to the cart widget based on address field entered/changed.

enter image description here

Is there any Woocommerce hook which would let me update 'Local Delivery' value after address field is changed/entered?

I manipulate the address and based on address I add custom shipping cost.

closed as off-topic by Pieter Goosen, Robert hue, TheDeadMedic, Howdy_McGee, Mayeenul Islam Jun 16 '15 at 18:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

3

There is a similar question on StackOverflow, check the answer there. Hope this will help you.

Here is the code you can use:

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;
}

Basically what is important here is the class 'update_totals_on_change'. From here Woocommerce will handle everything by its functionality.

  • Much better, this is now a proper answer. Removed my downvote :-) – Pieter Goosen Jun 15 '15 at 13:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.