Created
January 12, 2026 14:05
-
-
Save xlplugins/d92c6a3d5b9766289e390848a38877fb to your computer and use it in GitHub Desktop.
Prevent address field changes from triggering update_order_review AJAX calls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class WFACP_Prevent_Address_Field_Updates { | |
| /** | |
| * Address fields that shouldn't trigger order review updates | |
| * | |
| * @var array | |
| */ | |
| private $address_fields = array( | |
| 'billing_postcode', | |
| 'billing_city', | |
| 'billing_address_1', | |
| 'billing_address_2', | |
| 'billing_state', | |
| 'billing_country', | |
| 'billing_company', | |
| 'shipping_postcode', | |
| 'shipping_city', | |
| 'shipping_address_1', | |
| 'shipping_address_2', | |
| 'shipping_state', | |
| 'shipping_country', | |
| 'shipping_company', | |
| ); | |
| /** | |
| * Constructor | |
| */ | |
| public function __construct() { | |
| // Only run if FunnelKit Checkout is active | |
| if ( ! class_exists( 'WFACP_Core' ) ) { | |
| return; | |
| } | |
| // Hook into WFACP field filters | |
| add_filter( 'wfacp_billing_field', array( $this, 'remove_update_totals_class' ), 10, 2 ); | |
| add_filter( 'wfacp_shipping_field', array( $this, 'remove_update_totals_class' ), 10, 2 ); | |
| // Also handle default address fields filter as a fallback | |
| add_filter( 'wfacp_default_billing_address_fields', array( $this, 'remove_update_totals_from_default_fields' ), 20 ); | |
| add_filter( 'wfacp_default_shipping_address_fields', array( $this, 'remove_update_totals_from_default_fields' ), 20 ); | |
| } | |
| /** | |
| * Remove update_totals_on_change class from address fields | |
| * | |
| * @param array $field Field configuration array | |
| * @param string $key Field key (e.g., 'billing_postcode') | |
| * @return array Modified field configuration | |
| */ | |
| public function remove_update_totals_class( $field, $key ) { | |
| // Check if this is an address field we want to modify | |
| if ( ! in_array( $key, $this->address_fields, true ) ) { | |
| return $field; | |
| } | |
| // Ensure class is an array | |
| if ( ! isset( $field['class'] ) || ! is_array( $field['class'] ) ) { | |
| return $field; | |
| } | |
| // Remove update_totals_on_change class | |
| $field['class'] = array_values( array_diff( $field['class'], array( 'update_totals_on_change' ) ) ); | |
| return $field; | |
| } | |
| /** | |
| * Remove update_totals_on_change from default address fields | |
| * | |
| * This handles fields that might be added via the default fields filter | |
| * Note: Default fields have keys without 'billing_'/'shipping_' prefix (e.g., 'postcode', 'city') | |
| * | |
| * @param array $fields Default address fields array | |
| * @return array Modified fields array | |
| */ | |
| public function remove_update_totals_from_default_fields( $fields ) { | |
| if ( ! is_array( $fields ) ) { | |
| return $fields; | |
| } | |
| // Fields that should not trigger updates (without prefix) | |
| $default_field_keys = array( 'postcode', 'city', 'address_1', 'address_2', 'state', 'country', 'company' ); | |
| foreach ( $fields as $key => $field ) { | |
| // Check if this is an address field we want to modify | |
| // Default fields have keys like 'postcode', 'city', etc. (without prefix) | |
| if ( ! in_array( $key, $default_field_keys, true ) ) { | |
| continue; | |
| } | |
| // Ensure class is an array | |
| if ( ! isset( $field['class'] ) || ! is_array( $field['class'] ) ) { | |
| continue; | |
| } | |
| // Remove update_totals_on_change class | |
| $fields[ $key ]['class'] = array_values( array_diff( $field['class'], array( 'update_totals_on_change' ) ) ); | |
| } | |
| return $fields; | |
| } | |
| } | |
| // Initialize the address field update prevention | |
| // Works specifically with FunnelKit Checkout (WFACP) | |
| if ( function_exists( 'is_checkout' ) && class_exists( 'WFACP_Core' ) ) { | |
| new WFACP_Prevent_Address_Field_Updates(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment