-
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.
fix: use Woo's cart fee for covering transaction fees (#2820)
- Loading branch information
1 parent
1af3c23
commit fded027
Showing
2 changed files
with
117 additions
and
83 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