-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2827 from Automattic/master
Alpha release Dec 22
- Loading branch information
Showing
13 changed files
with
903 additions
and
259 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* globals jQuery, newspack_wc_cover_fees */ | ||
( function ( $ ) { | ||
if ( ! $ ) { | ||
return; | ||
} | ||
const $body = $( document.body ); | ||
$body.on( 'init_checkout', function () { | ||
const form = document.querySelector( 'form.checkout' ); | ||
if ( ! form ) { | ||
return; | ||
} | ||
let checked = document.getElementById( newspack_wc_cover_fees.custom_field_name )?.checked; | ||
form.addEventListener( 'change', function () { | ||
// Get element on every change because the DOM is replaced by AJAX. | ||
const input = document.getElementById( newspack_wc_cover_fees.custom_field_name ); | ||
if ( ! input ) { | ||
return; | ||
} | ||
if ( checked !== input.checked ) { | ||
checked = input.checked; | ||
$body.trigger( 'update_checkout', { update_shipping_method: false } ); | ||
} | ||
} ); | ||
// Trigger checkout update on payment method change so it updates the fee. | ||
$( document ).on( 'payment_method_selected', function () { | ||
$body.trigger( 'update_checkout', { update_shipping_method: false } ); | ||
} ); | ||
} ); | ||
} )( jQuery ); |
This file contains 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
This file contains 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
Oops, something went wrong.