Hi @jansku, @mixbee, and @gustavolessa,
You can use the code snippets below to make the postcode
field — along with the city
and state
fields — trigger updating the checkout sections.
/**
* Change shipping field attributes to trigger checkout update.
*/
function fluidcheckout_change_shipping_address_fields_args( $fields ) {
if ( array_key_exists( 'shipping_state', $fields ) ) { $fields[ 'shipping_state' ][ 'class' ][] = 'update_totals_on_change'; }
if ( array_key_exists( 'shipping_city', $fields ) ) { $fields[ 'shipping_city' ][ 'class' ][] = 'update_totals_on_change'; }
if ( array_key_exists( 'shipping_postcode', $fields ) ) { $fields[ 'shipping_postcode' ][ 'class' ][] = 'update_totals_on_change'; }
return $fields;
}
add_filter( 'woocommerce_shipping_fields', 'fluidcheckout_change_shipping_address_fields_args', 300 );
/**
* Change billing field attributes to trigger checkout update.
*/
function fluidcheckout_change_billing_address_fields_args( $fields ) {
if ( array_key_exists( 'billing_state', $fields ) ) { $fields[ 'billing_state' ][ 'class' ][] = 'update_totals_on_change'; }
if ( array_key_exists( 'billing_city', $fields ) ) { $fields[ 'billing_city' ][ 'class' ][] = 'update_totals_on_change'; }
if ( array_key_exists( 'billing_postcode', $fields ) ) { $fields[ 'billing_postcode' ][ 'class' ][] = 'update_totals_on_change'; }
return $fields;
}
add_filter( 'woocommerce_billing_fields', 'fluidcheckout_change_billing_address_fields_args', 300 );
If you are unsure about how to add the code snippet, check our article:
How to safely add code snippets to your WooCommerce website
Please note that the Country field needs to have a valid value for the other fields to trigger the checkout section update. This is how the WooCommerce script works.
I’m closing this topic for now. If you need further assistance, please reply to this topic.
Best,
Diego