mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
✨ Always show smart buttons in ‘preview’ context
This commit is contained in:
parent
e9e94e277c
commit
71c19d8034
2 changed files with 14 additions and 3 deletions
|
@ -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' );
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue