Skip to content

Commit

Permalink
Fix WooPay duplicated Save my info section (#9531)
Browse files Browse the repository at this point in the history
Co-authored-by: Danae Millan <[email protected]>
  • Loading branch information
alefesouza and a-danae authored Oct 22, 2024
1 parent 1652cc9 commit 439c151
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-woopay-duplicated-component
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix WooPay duplicated Save my info section.
43 changes: 25 additions & 18 deletions client/checkout/woopay/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,38 @@ const renderSaveUserSection = () => {
);

if ( blocksCheckout.length ) {
const checkoutPageSaveUserContainer = document.createElement(
'fieldset'
let checkoutPageSaveUserContainer = document.querySelector(
'#remember-me'
);
const paymentOptions = document.getElementsByClassName(
'wp-block-woocommerce-checkout-payment-block'
)?.[ 0 ];

checkoutPageSaveUserContainer.className =
'wc-block-checkout__payment-method wp-block-woocommerce-checkout-remember-block wc-block-components-checkout-step ';
checkoutPageSaveUserContainer.id = 'remember-me';
if ( ! checkoutPageSaveUserContainer ) {
const paymentOptions = document.getElementsByClassName(
'wp-block-woocommerce-checkout-payment-block'
)?.[ 0 ];

if ( paymentOptions ) {
// Render right after the payment options block, as a sibling element.
paymentOptions.parentNode.insertBefore(
checkoutPageSaveUserContainer,
paymentOptions.nextSibling
checkoutPageSaveUserContainer = document.createElement(
'fieldset'
);

paymentOptions.classList.add( 'is-woopay' );
checkoutPageSaveUserContainer.className =
'wc-block-checkout__payment-method wp-block-woocommerce-checkout-remember-block wc-block-components-checkout-step ';
checkoutPageSaveUserContainer.id = 'remember-me';

ReactDOM.render(
<CheckoutPageSaveUser isBlocksCheckout={ true } />,
checkoutPageSaveUserContainer
);
if ( paymentOptions ) {
// Render right after the payment options block, as a sibling element.
paymentOptions.parentNode.insertBefore(
checkoutPageSaveUserContainer,
paymentOptions.nextSibling
);

paymentOptions.classList.add( 'is-woopay' );
}
}

ReactDOM.render(
<CheckoutPageSaveUser isBlocksCheckout={ true } />,
checkoutPageSaveUserContainer
);
} else {
const checkoutPageSaveUserContainer = document.createElement( 'div' );
checkoutPageSaveUserContainer.className =
Expand Down

0 comments on commit 439c151

Please sign in to comment.