Skip to content

Commit

Permalink
πŸ› Refresh cart when exiting Ryan flow
Browse files Browse the repository at this point in the history
After restoring the original WooCommerce form, also trigger a cart refresh Ajax call
  • Loading branch information
stracker-phil committed Oct 1, 2024
1 parent d8d87ce commit 41e69fe
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions modules/ppcp-axo/resources/js/Components/FormFieldGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,28 @@ class FormFieldGroup {
* This function iterates through the stored form fields and resets their values or states.
*/
restoreFormData() {
let formHasChanged = false;

// Reset form fields to their initial state.
this.loopFields( ( { inputSelector }, fieldKey ) => {
if ( inputSelector && this.#stored.has( fieldKey ) ) {
const elInput = document.querySelector( inputSelector );
if ( ! this.#stored.has( fieldKey ) ) {
return;
}

this.#setFieldValue( elInput, this.#stored.get( fieldKey ) );
this.#stored.delete( fieldKey );
const elInput = inputSelector
? document.querySelector( inputSelector )
: null;
const oldValue = this.#stored.get( fieldKey );
this.#stored.delete( fieldKey );

if ( this.#setFieldValue( elInput, oldValue ) ) {
formHasChanged = true;
}
} );

if ( formHasChanged ) {
document.body.dispatchEvent( new Event( 'update_checkout' ) );
}
}

/**
Expand Down

0 comments on commit 41e69fe

Please sign in to comment.