2
votes

I'm currently working on a custom shipping method plugin for WooCommerce. In order to calculate the cost of shipping I need access to the customer's phone number and/or email address.

At the moment I can see the checkout shipping methods are refreshed for specific checkout fields as postcode, city, state or country when changing or entering a value in the checkout page.

How can I trigger this same reload when the user enters their email or phone number?

1

1 Answers

4
votes

That is very simeple as you will seeā€¦ It can be done just adding 'update_totals_on_change' to billing email and phone fields wrapper class, this way:

add_filter( 'woocommerce_checkout_fields' , 'trigger_update_checkout_on_change' );
function trigger_update_checkout_on_change( $fields ) {

    $fields['billing']['billing_phone']['class'][] = 'update_totals_on_change';
    $fields['billing']['billing_email']['class'][] = 'update_totals_on_change';

    return $fields;
}

Code goes in functions.php file of your active child theme (or active theme). Tested and works.


But sometimes depending on your code, it will be not enough.