Always show smart buttons in ‘preview’ context

This commit is contained in:
Philipp Stracker 2024-11-29 11:59:48 +01:00
parent e9e94e277c
commit 71c19d8034
No known key found for this signature in database
2 changed files with 14 additions and 3 deletions

View file

@ -7,6 +7,7 @@ import {
handleShippingOptionsChange,
handleShippingAddressChange,
} from '../Helper/ShippingHandler.js';
import { PaymentContext } from '../Helper/CheckoutMethodState';
class Renderer {
constructor(
@ -35,6 +36,10 @@ class Renderer {
* @return {boolean} True, if smart buttons are present on the page.
*/
get useSmartButtons() {
if ( PaymentContext.Preview === this.defaultSettings?.context ) {
return true;
}
const components = this.defaultSettings?.url_params?.components || '';
return components.split( ',' ).includes( 'buttons' );

View file

@ -11,6 +11,7 @@ import {
isVisible,
} from '../../../ppcp-button/resources/js/modules/Helper/Hiding';
import widgetBuilder from '../../../ppcp-button/resources/js/modules/Renderer/WidgetBuilder';
import { PaymentContext } from '../../../ppcp-button/resources/js/modules/Helper/CheckoutMethodState';
document.addEventListener( 'DOMContentLoaded', () => {
function disableAll( nodeList ) {
@ -134,7 +135,12 @@ document.addEventListener( 'DOMContentLoaded', () => {
function createButtonPreview( settingsCallback ) {
const render = ( settings ) => {
const { button, separate_buttons } = settings;
const previewSettings = {
context: PaymentContext.Preview,
...settings,
};
const { button, separate_buttons } = previewSettings;
const wrapperSelector = (
Object.values( separate_buttons )[ 0 ] ?? button
)?.wrapper;
@ -147,7 +153,7 @@ document.addEventListener( 'DOMContentLoaded', () => {
const renderer = new Renderer(
null,
settings,
previewSettings,
( data, actions ) => actions.reject(),
null
);
@ -156,7 +162,7 @@ document.addEventListener( 'DOMContentLoaded', () => {
renderer.render( {} );
jQuery( document ).trigger(
'ppcp_paypal_render_preview',
settings
previewSettings
);
} catch ( err ) {
console.error( err );