' ).text( error.message || paypal_standard.generic_error_message ).html();
const messageWrapper =
'
- ' +
sanitizedErrorMessage +
'
';
const $noticeContainer = $( '.woocommerce-notices-wrapper' ).first();
if ( ! $noticeContainer.length ) {
return;
}
$(
'.woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message'
).remove();
$noticeContainer.prepend( messageWrapper );
},
});
if ( buttons.hasReturned() ) {
// App Switch resume flow.
buttons.resume();
}
buttons.render( container ).catch( function ( err ) {
// eslint-disable-next-line no-console
console.error( 'Failed to render PayPal buttons', err );
});
}
// Align the PayPal buttons to the center of the container on classic checkout page.
function applyStyles() {
const paypalContainer = document.getElementById( containerSelector );
const containerWidth = paypalContainer.offsetWidth;
// PayPal buttons have max-width: 750px inside the iframe.
// Calculate the left margin to center a 750px button container.
const leftMargin = Math.max( 0, ( containerWidth - 750 ) / 2 );
paypalContainer.style.marginLeft = leftMargin + 'px';
}
// Re-render when cart is updated and the html is rerendered on the Cart page.
$( document.body ).on( 'updated_cart_totals', function () {
// If the container was replaced, re-render PayPal buttons
const buttonsContainer = document.getElementById( containerSelector );
if ( buttonsContainer && ! buttonsContainer.querySelector( 'iframe' ) ) {
renderButtons();
}
} );
renderButtons();
});