From 9c7ac6ba341fc0b954a22c330363d5d36fecd385 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 5 Dec 2022 15:27:58 +0400 Subject: [PATCH 01/17] Organize settings fields in separate folder --- modules/ppcp-wc-gateway/extensions.php | 11 +- modules/ppcp-wc-gateway/services.php | 648 +-------------- .../Fields/connection-tab-fields.php} | 3 +- .../Settings/Fields/pay-later-tab-fields.php} | 9 +- .../Fields/paypal-smart-button-fields.php | 745 ++++++++++++++++++ 5 files changed, 770 insertions(+), 646 deletions(-) rename modules/ppcp-wc-gateway/{connection-tab-settings.php => src/Settings/Fields/connection-tab-fields.php} (99%) rename modules/ppcp-wc-gateway/{pay-later-tab-settings.php => src/Settings/Fields/pay-later-tab-fields.php} (99%) create mode 100644 modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php diff --git a/modules/ppcp-wc-gateway/extensions.php b/modules/ppcp-wc-gateway/extensions.php index 68bcf2590..f41d19026 100644 --- a/modules/ppcp-wc-gateway/extensions.php +++ b/modules/ppcp-wc-gateway/extensions.php @@ -100,12 +100,17 @@ return array( }, 'wcgateway.settings.fields' => function ( ContainerInterface $container, array $fields ): array { - $get_connection_tab_fields = require __DIR__ . '/connection-tab-settings.php'; + $path_to_settings_fields = __DIR__ . '/src/Settings/Fields'; + + $get_paypal_button_fields = require $path_to_settings_fields . '/paypal-smart-button-fields.php'; + $paypal_button_fields = $get_paypal_button_fields( $container, $fields ) ?? array(); + + $get_connection_tab_fields = require $path_to_settings_fields . '/connection-tab-fields.php'; $connection_tab_fields = $get_connection_tab_fields( $container, $fields ) ?? array(); - $get_pay_later_tab_fields = require __DIR__ . '/pay-later-tab-settings.php'; + $get_pay_later_tab_fields = require $path_to_settings_fields . '/pay-later-tab-fields.php'; $pay_later_tab_fields = $get_pay_later_tab_fields( $container, $fields ) ?? array(); - return array_merge( $connection_tab_fields, $pay_later_tab_fields ); + return array_merge( $paypal_button_fields, $connection_tab_fields, $pay_later_tab_fields ); }, ); diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 9de3f627f..0664e15a9 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -432,19 +432,9 @@ return array( $onboarding_options_renderer = $container->get( 'onboarding.render-options' ); assert( $onboarding_options_renderer instanceof OnboardingOptionsRenderer ); - $render_preview_element = function ( string $id ): string { - return ' -
-

' . __( 'Preview', 'woocommerce-paypal-payments' ) . '

-
-
'; - }; - $subscription_helper = $container->get( 'subscription.helper' ); assert( $subscription_helper instanceof SubscriptionHelper ); - $has_enabled_separate_button_gateways = $container->get( 'wcgateway.settings.has_enabled_separate_button_gateways' ); - $fields = array( 'checkout_settings_heading' => array( 'heading' => __( 'Standard Payments Settings', 'woocommerce-paypal-payments' ), @@ -710,627 +700,6 @@ return array( 'gateway' => 'paypal', ), - // General button styles. - 'button_style_heading' => array( - 'heading' => __( 'Checkout Buttons', 'woocommerce-paypal-payments' ), - 'type' => 'ppcp-heading', - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - 'description' => sprintf( - // translators: %1$s and %2$s are the opening and closing of HTML tag. - __( 'Customize the appearance of the PayPal smart buttons on the %1$sCheckout page%2$s.', 'woocommerce-paypal-payments' ), - '', - '' - ), - ), - 'button_enabled' => array( - 'title' => __( 'Enable buttons on Checkout', 'woocommerce-paypal-payments' ), - 'type' => 'checkbox', - 'label' => __( 'Enable on Checkout', 'woocommerce-paypal-payments' ), - 'default' => true, - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_layout' => array( - 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'classes' => $has_enabled_separate_button_gateways ? array( 'hide' ) : array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'vertical', - 'desc_tip' => true, - 'description' => __( - 'If additional funding sources are available to the buyer through PayPal, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), - 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_tagline' => array( - 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), - 'type' => 'checkbox', - 'default' => false, - 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), - 'desc_tip' => true, - 'description' => __( - 'Add the tagline. This line will only show up, if you select a horizontal layout.', - 'woocommerce-paypal-payments' - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_label' => array( - 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - /** - * Returns default label ID of the PayPal button. - */ - 'default' => apply_filters( 'woocommerce_paypal_payments_button_label_default', 'paypal' ), - 'desc_tip' => true, - 'description' => __( - 'This controls the label on the primary button.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), - 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), - 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), - 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_color' => array( - 'title' => __( 'Color', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'gold', - 'desc_tip' => true, - 'description' => __( - 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), - 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), - 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), - 'black' => __( 'Black', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_shape' => array( - 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'rect', - 'desc_tip' => true, - 'description' => __( - 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), - 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_preview' => array( - 'type' => 'ppcp-text', - 'text' => $render_preview_element( 'ppcpCheckoutButtonPreview' ), - 'screens' => array( - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - - // Single product page. - 'button_product_heading' => array( - 'heading' => __( 'Single Product Page Buttons', 'woocommerce-paypal-payments' ), - 'type' => 'ppcp-heading', - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - 'description' => sprintf( - // translators: %1$s and %2$s are the opening and closing of HTML tag. - __( 'Customize the appearance of the PayPal smart buttons on the %1$sSingle Product Page%2$s.', 'woocommerce-paypal-payments' ), - '', - '' - ), - ), - 'button_product_enabled' => array( - 'title' => __( 'Enable buttons on Single Product', 'woocommerce-paypal-payments' ), - 'type' => 'checkbox', - 'label' => __( 'Enable on Single Product', 'woocommerce-paypal-payments' ), - 'default' => true, - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_product_layout' => array( - 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'horizontal', - 'desc_tip' => true, - 'description' => __( - 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), - 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_product_tagline' => array( - 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), - 'type' => 'checkbox', - 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), - 'default' => false, - 'desc_tip' => true, - 'description' => __( - 'Add the tagline. This line will only show up, if you select a horizontal layout.', - 'woocommerce-paypal-payments' - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_product_label' => array( - 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - /** - * Returns default label ID of the PayPal button on product pages. - */ - 'default' => apply_filters( 'woocommerce_paypal_payments_button_product_label_default', 'paypal' ), - 'desc_tip' => true, - 'description' => __( - 'This controls the label on the primary button.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), - 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), - 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), - 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_product_color' => array( - 'title' => __( 'Color', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'gold', - 'desc_tip' => true, - 'description' => __( - 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), - 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), - 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), - 'black' => __( 'Black', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_product_shape' => array( - 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'rect', - 'desc_tip' => true, - 'description' => __( - 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), - 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_product_preview' => array( - 'type' => 'ppcp-text', - 'text' => $render_preview_element( 'ppcpProductButtonPreview' ), - 'screens' => array( - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - - // Cart settings. - 'button_cart_heading' => array( - 'heading' => __( 'Cart Buttons', 'woocommerce-paypal-payments' ), - 'type' => 'ppcp-heading', - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - 'description' => sprintf( - // translators: %1$s and %2$s are the opening and closing of HTML tag. - __( 'Customize the appearance of the PayPal smart buttons %1$son the Cart page%2$s.', 'woocommerce-paypal-payments' ), - '', - '' - ), - ), - 'button_cart_enabled' => array( - 'title' => __( 'Enable buttons on Cart', 'woocommerce-paypal-payments' ), - 'type' => 'checkbox', - 'label' => __( 'Enable on Cart', 'woocommerce-paypal-payments' ), - 'default' => true, - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_cart_layout' => array( - 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'horizontal', - 'desc_tip' => true, - 'description' => __( - 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), - 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_cart_tagline' => array( - 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), - 'type' => 'checkbox', - 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), - 'default' => false, - 'desc_tip' => true, - 'description' => __( - 'Add the tagline. This line will only show up, if you select a horizontal layout.', - 'woocommerce-paypal-payments' - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_cart_label' => array( - 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - /** - * Returns default label ID of the PayPal button in cart. - */ - 'default' => apply_filters( 'woocommerce_paypal_payments_button_cart_label_default', 'paypal' ), - 'desc_tip' => true, - 'description' => __( - 'This controls the label on the primary button.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), - 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), - 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), - 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_cart_color' => array( - 'title' => __( 'Color', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'gold', - 'desc_tip' => true, - 'description' => __( - 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), - 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), - 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), - 'black' => __( 'Black', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_cart_shape' => array( - 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'rect', - 'desc_tip' => true, - 'description' => __( - 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), - 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_cart_preview' => array( - 'type' => 'ppcp-text', - 'text' => $render_preview_element( 'ppcpCartButtonPreview' ), - 'screens' => array( - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - - // Mini cart settings. - 'button_mini-cart_heading' => array( - 'heading' => __( 'Mini Cart Buttons', 'woocommerce-paypal-payments' ), - 'type' => 'ppcp-heading', - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - 'description' => sprintf( - // translators: %1$s and %2$s are the opening and closing of HTML tag. - __( 'Customize the appearance of the PayPal smart buttons %1$son the Mini Cart page%2$s.', 'woocommerce-paypal-payments' ), - '', - '' - ), - ), - 'button_mini-cart_enabled' => array( - 'title' => __( 'Enable buttons on Mini Cart', 'woocommerce-paypal-payments' ), - 'type' => 'checkbox', - 'label' => __( 'Enable on Mini Cart', 'woocommerce-paypal-payments' ), - 'default' => false, - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_mini-cart_layout' => array( - 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'vertical', - 'desc_tip' => true, - 'description' => __( - 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), - 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_mini-cart_tagline' => array( - 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), - 'type' => 'checkbox', - 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), - 'default' => false, - 'desc_tip' => true, - 'description' => __( - 'Add the tagline. This line will only show up, if you select a horizontal layout.', - 'woocommerce-paypal-payments' - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_mini-cart_label' => array( - 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - /** - * Returns default label ID of the PayPal button in mini cart. - */ - 'default' => apply_filters( 'woocommerce_paypal_payments_button_mini_cart_label_default', 'paypal' ), - 'desc_tip' => true, - 'description' => __( - 'This controls the label on the primary button.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), - 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), - 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), - 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_mini-cart_color' => array( - 'title' => __( 'Color', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'gold', - 'desc_tip' => true, - 'description' => __( - 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), - 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), - 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), - 'black' => __( 'Black', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_mini-cart_shape' => array( - 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'rect', - 'desc_tip' => true, - 'description' => __( - 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), - 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_mini-cart_height' => array( - 'title' => __( 'Button Height', 'woocommerce-paypal-payments' ), - 'type' => 'number', - 'default' => '35', - 'custom_attributes' => array( - 'min' => 25, - 'max' => 55, - ), - 'desc_tip' => true, - 'description' => __( 'Add a value from 25 to 55.', 'woocommerce-paypal-payments' ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_mini-cart_preview' => array( - 'type' => 'ppcp-text', - 'text' => $render_preview_element( 'ppcpMiniCartButtonPreview' ), - 'screens' => array( - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'disable_cards' => array( 'title' => __( 'Disable specific credit cards', 'woocommerce-paypal-payments' ), 'type' => 'ppcp-multiselect', @@ -1893,13 +1262,22 @@ return array( 'dcc.status-cache' => static function( ContainerInterface $container ): Cache { return new Cache( 'ppcp-paypal-dcc-status-cache' ); }, - 'wcgateway.settings.pay-later.messaging-locations' => static function( ContainerInterface $container ): array { + 'wcgateway.button.locations' => static function( ContainerInterface $container ): array { return array( - 'product' => 'Single Product', - 'cart' => 'Cart', - 'checkout' => 'Checkout', + 'product' => 'Single Product', + 'cart' => 'Cart', + 'checkout' => 'Checkout', + 'mini-cart' => 'Mini Cart', ); }, + 'wcgateway.settings.pay-later.messaging-locations' => static function( ContainerInterface $container ): array { + $button_locations = $container->get( 'wcgateway.button.locations' ); + unset( $button_locations['mini-cart'] ); + return $button_locations; + }, + 'wcgateway.button.default-locations' => static function( ContainerInterface $container ): array { + return array_keys( $container->get( 'wcgateway.settings.pay-later.messaging-locations' ) ); + }, 'wcgateway.settings.pay-later.button-locations' => static function( ContainerInterface $container ): array { $button_locations = array(); diff --git a/modules/ppcp-wc-gateway/connection-tab-settings.php b/modules/ppcp-wc-gateway/src/Settings/Fields/connection-tab-fields.php similarity index 99% rename from modules/ppcp-wc-gateway/connection-tab-settings.php rename to modules/ppcp-wc-gateway/src/Settings/Fields/connection-tab-fields.php index edc38d8ec..1878fd5e3 100644 --- a/modules/ppcp-wc-gateway/connection-tab-settings.php +++ b/modules/ppcp-wc-gateway/src/Settings/Fields/connection-tab-fields.php @@ -9,14 +9,13 @@ declare(strict_types=1); -namespace WooCommerce\PayPalCommerce\WcGateway; +namespace WooCommerce\PayPalCommerce\WcGateway\Settings; use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies; use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer; use WooCommerce\PayPalCommerce\Onboarding\State; -use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; return function ( ContainerInterface $container, array $fields ): array { diff --git a/modules/ppcp-wc-gateway/pay-later-tab-settings.php b/modules/ppcp-wc-gateway/src/Settings/Fields/pay-later-tab-fields.php similarity index 99% rename from modules/ppcp-wc-gateway/pay-later-tab-settings.php rename to modules/ppcp-wc-gateway/src/Settings/Fields/pay-later-tab-fields.php index e0855f836..fab61ca83 100644 --- a/modules/ppcp-wc-gateway/pay-later-tab-settings.php +++ b/modules/ppcp-wc-gateway/src/Settings/Fields/pay-later-tab-fields.php @@ -9,11 +9,10 @@ declare(strict_types=1); -namespace WooCommerce\PayPalCommerce\WcGateway; +namespace WooCommerce\PayPalCommerce\WcGateway\Settings; use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; -use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; return function ( ContainerInterface $container, array $fields ): array { @@ -32,8 +31,6 @@ return function ( ContainerInterface $container, array $fields ): array { ? __( "You have PayPal vaulting enabled, that's why Pay Later options are unavailable now. You cannot use both features at the same time.", 'woocommerce-paypal-payments' ) : __( 'Enabled', 'woocommerce-paypal-payments' ); - $default_locations = array_keys( $container->get( 'wcgateway.settings.pay-later.messaging-locations' ) ); - $selected_country = $container->get( 'api.shop.country' ); $default_messaging_flex_color = $selected_country === 'US' ? 'white-no-border' : 'white'; @@ -75,7 +72,7 @@ return function ( ContainerInterface $container, array $fields ): array { 'type' => 'ppcp-multiselect', 'class' => array(), 'input_class' => array( 'wc-enhanced-select' ), - 'default' => $default_locations, + 'default' => $container->get( 'wcgateway.button.default-locations' ), 'desc_tip' => false, 'description' => __( 'Select where the Pay Later button should be displayed.', 'woocommerce-paypal-payments' ), 'options' => $container->get( 'wcgateway.settings.pay-later.button-locations' ), @@ -121,7 +118,7 @@ return function ( ContainerInterface $container, array $fields ): array { 'type' => 'ppcp-multiselect', 'class' => array(), 'input_class' => array( 'wc-enhanced-select' ), - 'default' => $default_locations, + 'default' => $container->get( 'wcgateway.button.default-locations' ), 'desc_tip' => false, 'description' => __( 'Select where the Pay Later messaging should be displayed.', 'woocommerce-paypal-payments' ), 'options' => $container->get( 'wcgateway.settings.pay-later.messaging-locations' ), diff --git a/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php b/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php new file mode 100644 index 000000000..2903355b4 --- /dev/null +++ b/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php @@ -0,0 +1,745 @@ +get( 'wcgateway.current-ppcp-settings-page-id' ); + + if ( $current_page_id !== PayPalGateway::ID ) { + return $fields; + } + + $settings = $container->get( 'wcgateway.settings' ); + assert( $settings instanceof Settings ); + + $has_enabled_separate_button_gateways = $container->get( 'wcgateway.settings.has_enabled_separate_button_gateways' ); + + $render_preview_element = function ( string $id ): string { + return ' +
+

' . __( 'Preview', 'woocommerce-paypal-payments' ) . '

+
+
'; + }; + + $smart_button_fields = array( + 'button_style_heading' => array( + 'heading' => __( 'PayPal Smart Buttons', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + 'description' => sprintf( + // translators: %1$s and %2$s are the opening and closing of HTML tag. + __( 'Customize the appearance of the PayPal smart buttons on the + %1$sCheckout page%5$s, %2$sSingle Product Page%5$s, %3$sCart page%5$s or on %4$sMini Cart page%5$s.', 'woocommerce-paypal-payments' ), + '', + '', + '', + '', + '' + ), + ), + 'smart_button_locations' => array( + 'title' => __( 'Smart Button Locations', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-multiselect', + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => $container->get( 'wcgateway.button.default-locations' ), + 'description' => __( 'Select where the PayPal smart buttons should be displayed.', 'woocommerce-paypal-payments' ), + 'options' => $container->get( 'wcgateway.button.locations' ), + 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'smart_button_enable_styling_per_location' => array( + 'title' => __( 'Customize Smart Buttons Per Location', 'woocommerce-paypal-payments' ), + 'type' => 'checkbox', + 'label' => __( 'Customize smart button style per location', 'woocommerce-paypal-payments' ), + 'default' => true, + 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + // General button styles. + 'button_general_layout' => array( + 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'classes' => $has_enabled_separate_button_gateways ? array( 'hide' ) : array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'vertical', + 'desc_tip' => true, + 'description' => __( + 'If additional funding sources are available to the buyer through PayPal, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), + 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_general_tagline' => array( + 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), + 'type' => 'checkbox', + 'default' => false, + 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), + 'desc_tip' => true, + 'description' => __( + 'Add the tagline. This line will only show up, if you select a horizontal layout.', + 'woocommerce-paypal-payments' + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_general_label' => array( + 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + /** + * Returns default label ID of the PayPal button. + */ + 'default' => apply_filters( 'woocommerce_paypal_payments_button_label_default', 'paypal' ), + 'desc_tip' => true, + 'description' => __( + 'This controls the label on the primary button.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), + 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), + 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), + 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_general_color' => array( + 'title' => __( 'Color', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'gold', + 'desc_tip' => true, + 'description' => __( + 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), + 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), + 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), + 'black' => __( 'Black', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_general_shape' => array( + 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'rect', + 'desc_tip' => true, + 'description' => __( + 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), + 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_general_preview' => array( + 'type' => 'ppcp-text', + 'text' => $render_preview_element( 'ppcpGeneralButtonPreview' ), + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + + // Checkout page. + 'button_checkout_heading' => array( + 'heading' => __( 'Smart Buttons on checkout', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_layout' => array( + 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'classes' => $has_enabled_separate_button_gateways ? array( 'hide' ) : array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'vertical', + 'desc_tip' => true, + 'description' => __( + 'If additional funding sources are available to the buyer through PayPal, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), + 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_tagline' => array( + 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), + 'type' => 'checkbox', + 'default' => false, + 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), + 'desc_tip' => true, + 'description' => __( + 'Add the tagline. This line will only show up, if you select a horizontal layout.', + 'woocommerce-paypal-payments' + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_label' => array( + 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + /** + * Returns default label ID of the PayPal button. + */ + 'default' => apply_filters( 'woocommerce_paypal_payments_button_label_default', 'paypal' ), + 'desc_tip' => true, + 'description' => __( + 'This controls the label on the primary button.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), + 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), + 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), + 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_color' => array( + 'title' => __( 'Color', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'gold', + 'desc_tip' => true, + 'description' => __( + 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), + 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), + 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), + 'black' => __( 'Black', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_shape' => array( + 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'rect', + 'desc_tip' => true, + 'description' => __( + 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), + 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_preview' => array( + 'type' => 'ppcp-text', + 'text' => $render_preview_element( 'ppcpCheckoutButtonPreview' ), + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + + // Single product page. + 'button_product_heading' => array( + 'heading' => __( 'Smart Buttons on Single Product', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_layout' => array( + 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'horizontal', + 'desc_tip' => true, + 'description' => __( + 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), + 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_tagline' => array( + 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), + 'type' => 'checkbox', + 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), + 'default' => false, + 'desc_tip' => true, + 'description' => __( + 'Add the tagline. This line will only show up, if you select a horizontal layout.', + 'woocommerce-paypal-payments' + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_label' => array( + 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + /** + * Returns default label ID of the PayPal button on product pages. + */ + 'default' => apply_filters( 'woocommerce_paypal_payments_button_product_label_default', 'paypal' ), + 'desc_tip' => true, + 'description' => __( + 'This controls the label on the primary button.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), + 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), + 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), + 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_color' => array( + 'title' => __( 'Color', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'gold', + 'desc_tip' => true, + 'description' => __( + 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), + 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), + 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), + 'black' => __( 'Black', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_shape' => array( + 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'rect', + 'desc_tip' => true, + 'description' => __( + 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), + 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_preview' => array( + 'type' => 'ppcp-text', + 'text' => $render_preview_element( 'ppcpProductButtonPreview' ), + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + + // Cart settings. + 'button_cart_heading' => array( + 'heading' => __( 'Smart Buttons on Cart', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_layout' => array( + 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'horizontal', + 'desc_tip' => true, + 'description' => __( + 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), + 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_tagline' => array( + 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), + 'type' => 'checkbox', + 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), + 'default' => false, + 'desc_tip' => true, + 'description' => __( + 'Add the tagline. This line will only show up, if you select a horizontal layout.', + 'woocommerce-paypal-payments' + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_label' => array( + 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + /** + * Returns default label ID of the PayPal button in cart. + */ + 'default' => apply_filters( 'woocommerce_paypal_payments_button_cart_label_default', 'paypal' ), + 'desc_tip' => true, + 'description' => __( + 'This controls the label on the primary button.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), + 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), + 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), + 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_color' => array( + 'title' => __( 'Color', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'gold', + 'desc_tip' => true, + 'description' => __( + 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), + 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), + 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), + 'black' => __( 'Black', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_shape' => array( + 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'rect', + 'desc_tip' => true, + 'description' => __( + 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), + 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_preview' => array( + 'type' => 'ppcp-text', + 'text' => $render_preview_element( 'ppcpCartButtonPreview' ), + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + + // Mini cart settings. + 'button_mini-cart_heading' => array( + 'heading' => __( 'Smart Buttons on Mini Cart', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_layout' => array( + 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'vertical', + 'desc_tip' => true, + 'description' => __( + 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), + 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_tagline' => array( + 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), + 'type' => 'checkbox', + 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), + 'default' => false, + 'desc_tip' => true, + 'description' => __( + 'Add the tagline. This line will only show up, if you select a horizontal layout.', + 'woocommerce-paypal-payments' + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_label' => array( + 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + /** + * Returns default label ID of the PayPal button in mini cart. + */ + 'default' => apply_filters( 'woocommerce_paypal_payments_button_mini_cart_label_default', 'paypal' ), + 'desc_tip' => true, + 'description' => __( + 'This controls the label on the primary button.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), + 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), + 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), + 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_color' => array( + 'title' => __( 'Color', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'gold', + 'desc_tip' => true, + 'description' => __( + 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), + 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), + 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), + 'black' => __( 'Black', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_shape' => array( + 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'rect', + 'desc_tip' => true, + 'description' => __( + 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), + 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_height' => array( + 'title' => __( 'Button Height', 'woocommerce-paypal-payments' ), + 'type' => 'number', + 'default' => '35', + 'custom_attributes' => array( + 'min' => 25, + 'max' => 55, + ), + 'desc_tip' => true, + 'description' => __( 'Add a value from 25 to 55.', 'woocommerce-paypal-payments' ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_preview' => array( + 'type' => 'ppcp-text', + 'text' => $render_preview_element( 'ppcpMiniCartButtonPreview' ), + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + ); + + return array_merge( $fields, $smart_button_fields ); +}; From 9c6a8137762c665d5239ea821f5c748ff30ff8e8 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 5 Dec 2022 15:28:45 +0400 Subject: [PATCH 02/17] Refactor settings JS code to work for standard tab --- .../ppcp-onboarding/resources/js/settings.js | 136 +++++++++--------- .../resources/js/gateway-settings.js | 4 +- 2 files changed, 70 insertions(+), 70 deletions(-) diff --git a/modules/ppcp-onboarding/resources/js/settings.js b/modules/ppcp-onboarding/resources/js/settings.js index 625910e0a..d9078660a 100644 --- a/modules/ppcp-onboarding/resources/js/settings.js +++ b/modules/ppcp-onboarding/resources/js/settings.js @@ -7,6 +7,10 @@ document.addEventListener( const payLaterMessagingLocationsSelect = payLaterMessagingLocationsSelector + ' select'; const payLaterMessagingEnabledSelector = '#ppcp-pay_later_messaging_enabled'; + const smartButtonLocationsSelector = '#field-smart_button_locations'; + const smartButtonLocationsSelect = smartButtonLocationsSelector + ' select'; + const smartButtonSelectableLocations = payLaterMessagingSelectableLocations.concat('mini-cart'); + const groupToggle = (selector, group) => { const toggleElement = document.querySelector(selector); if (! toggleElement) { @@ -162,40 +166,47 @@ document.addEventListener( replace(); }; - const togglePayLaterMessagingInputsBySelectedLocations = ( - stylingPerMessagingSelector, - messagingLocationsSelector, + const toggleInputsBySelectedLocations = ( + stylingPerSelector, + locationsSelector, groupToShowOnChecked, - groupToHideOnChecked + groupToHideOnChecked, + inputType ) => { const payLaterMessagingEnabled = document.querySelector(payLaterMessagingEnabledSelector); - const stylingPerMessagingElement = document.querySelector(stylingPerMessagingSelector); - const messagingLocationsElement = document.querySelector(messagingLocationsSelector); + const stylingPerElement = document.querySelector(stylingPerSelector); + const locationsElement = document.querySelector(locationsSelector); - if (! stylingPerMessagingElement) { + if (! stylingPerElement) { return; } const toggleElementsBySelectedLocations = () => { - if (! stylingPerMessagingElement.checked || ! payLaterMessagingEnabled.checked) { + if (! stylingPerElement.checked) { return; } - let checkedLocations = document.querySelectorAll(messagingLocationsSelector + ' :checked'); + if (inputType === 'messages' && ! payLaterMessagingEnabled.checked) { + return; + } + + let checkedLocations = document.querySelectorAll(locationsSelector + ' :checked'); const selectedLocations = [...checkedLocations].map(option => option.value); - const messagingInputSelectors = payLaterMessagingInputSelectorsByLocations(selectedLocations); + const inputSelectors = inputSelectorsByLocations(selectedLocations, inputType); groupToShowOnChecked.forEach( (element) => { - if ( messagingInputSelectors.includes(element) ) { + if ( inputSelectors.includes(element) ) { document.querySelector(element).style.display = ''; return; } document.querySelector(element).style.display = 'none'; }) - togglePayLaterMessageFields(); + if (inputType === 'messages') { + togglePayLaterMessageFields(); + } } const hideElements = (selectroGroup) => { @@ -210,14 +221,14 @@ document.addEventListener( }) } - groupToggle(stylingPerMessagingSelector, groupToShowOnChecked); + groupToggle(stylingPerSelector, groupToShowOnChecked); toggleElementsBySelectedLocations(); - if (stylingPerMessagingElement.checked) { + if (stylingPerElement.checked) { hideElements(groupToHideOnChecked); } - stylingPerMessagingElement.addEventListener( + stylingPerElement.addEventListener( 'change', (event) => { toggleElementsBySelectedLocations(); @@ -228,19 +239,23 @@ document.addEventListener( } showElements(groupToHideOnChecked); - togglePayLaterMessageFields(); + if (inputType === 'messages') { + togglePayLaterMessageFields(); + } } ); // We need to use jQuery here as the select might be a select2 element, which doesn't use native events. - jQuery(messagingLocationsElement).on('change', toggleElementsBySelectedLocations); + jQuery(locationsElement).on('change', toggleElementsBySelectedLocations); } - const payLaterMessagingInputSelectorsByLocations = (locations) => { + const inputSelectorsByLocations = (locations, inputType = 'messages') => { let inputSelectros = []; locations.forEach( (location) => { - inputSelectros = inputSelectros.concat(payLaterMessagingInputSelectorByLocation(location)) + inputSelectros = inputType === 'messages' + ? inputSelectros.concat(payLaterMessagingInputSelectorByLocation(location)) + : inputSelectros.concat(butttonInputSelectorByLocation(location)); }) return inputSelectros @@ -264,8 +279,30 @@ document.addEventListener( return inputSelectors } + const butttonInputSelectorByLocation = (location) => { + const locationPrefix = location === 'checkout' ? '' : '_' + location; + const inputSelectors = [ + '#field-button' + locationPrefix + '_layout', + '#field-button' + locationPrefix + '_tagline', + '#field-button' + locationPrefix + '_label', + '#field-button' + locationPrefix + '_color', + '#field-button' + locationPrefix + '_shape', + '#field-button' + locationPrefix + '_preview', + ] + + if (location !== 'general') { + inputSelectors.push('#field-button_' + location + '_heading'); + } + + if (location === 'mini-cart') { + inputSelectors.push('#field-button' + locationPrefix + '_height'); + } + + return inputSelectors + } + const allPayLaterMessaginginputSelectors = () => { - let stylingInputSelectors = payLaterMessagingInputSelectorsByLocations(payLaterMessagingAllLocations); + let stylingInputSelectors = inputSelectorsByLocations(payLaterMessagingAllLocations); return stylingInputSelectors.concat(payLaterMessagingLocationsSelector, '#field-pay_later_enable_styling_per_messaging_location'); } @@ -296,17 +333,6 @@ document.addEventListener( (() => { removeDisabledCardIcons('select[name="ppcp[disable_cards][]"]', 'select[name="ppcp[card_icons][]"]'); - groupToggle( - '#ppcp-button_enabled', - [ - '#field-button_layout', - '#field-button_tagline', - '#field-button_label', - '#field-button_color', - '#field-button_shape', - '#field-button_preview', - ] - ); groupToggle( '#ppcp-pay_later_button_enabled', @@ -315,49 +341,22 @@ document.addEventListener( toggleMessagingEnabled(); - togglePayLaterMessagingInputsBySelectedLocations( + toggleInputsBySelectedLocations( '#ppcp-pay_later_enable_styling_per_messaging_location', payLaterMessagingLocationsSelect, - payLaterMessagingInputSelectorsByLocations(payLaterMessagingSelectableLocations), - payLaterMessagingInputSelectorsByLocations(['general']), + inputSelectorsByLocations(payLaterMessagingSelectableLocations), + inputSelectorsByLocations(['general']), + 'messages' ); - groupToggle( - '#ppcp-button_product_enabled', - [ - '#field-button_product_layout', - '#field-button_product_tagline', - '#field-button_product_label', - '#field-button_product_color', - '#field-button_product_shape', - '#field-button_product_preview', - ] + toggleInputsBySelectedLocations( + '#ppcp-smart_button_enable_styling_per_location', + smartButtonLocationsSelect, + inputSelectorsByLocations(smartButtonSelectableLocations, 'buttons'), + inputSelectorsByLocations(['general'], 'buttons'), + 'buttons' ); - groupToggle( - '#ppcp-button_mini-cart_enabled', - [ - '#field-button_mini-cart_layout', - '#field-button_mini-cart_tagline', - '#field-button_mini-cart_label', - '#field-button_mini-cart_color', - '#field-button_mini-cart_shape', - '#field-button_mini-cart_height', - '#field-button_mini-cart_preview', - ] - ); - - groupToggle( - '#ppcp-button_cart_enabled', - [ - '#field-button_cart_layout', - '#field-button_cart_tagline', - '#field-button_cart_label', - '#field-button_cart_color', - '#field-button_cart_shape', - '#field-button_cart_preview', - ] - ); groupToggle( '#ppcp-vault_enabled', @@ -366,7 +365,6 @@ document.addEventListener( ] ); - groupToggleSelect( '#ppcp-intent', [ diff --git a/modules/ppcp-wc-gateway/resources/js/gateway-settings.js b/modules/ppcp-wc-gateway/resources/js/gateway-settings.js index b69e13445..6548412f8 100644 --- a/modules/ppcp-wc-gateway/resources/js/gateway-settings.js +++ b/modules/ppcp-wc-gateway/resources/js/gateway-settings.js @@ -45,11 +45,13 @@ import {setVisibleByClass, isVisible} from "../../../ppcp-button/resources/js/mo if (separateCardButtonCheckbox) { separateCardButtonCheckbox.addEventListener('change', () => { setVisibleByClass('#field-button_layout', !separateCardButtonCheckbox.checked, 'hide'); + setVisibleByClass('#field-button_general_layout', !separateCardButtonCheckbox.checked, 'hide'); }); } [ {layoutSelector: '#ppcp-button_layout', taglineSelector: '#field-button_tagline', canHaveSeparateButtons: true}, + {layoutSelector: '#ppcp-button_general_layout', taglineSelector: '#field-button_general_tagline', canHaveSeparateButtons: true}, {layoutSelector: '#ppcp-button_product_layout', taglineSelector: '#field-button_product_tagline'}, {layoutSelector: '#ppcp-button_cart_layout', taglineSelector: '#field-button_cart_tagline'}, {layoutSelector: '#ppcp-button_mini-cart_layout', taglineSelector: '#field-button_mini-cart_tagline'}, @@ -262,7 +264,7 @@ import {setVisibleByClass, isVisible} from "../../../ppcp-button/resources/js/mo loadPaypalScript(oldScriptSettings, () => { const payLaterMessagingLocations = ['product', 'cart', 'checkout', 'general']; - const paypalButtonLocations = ['product', 'cart', 'checkout', 'mini-cart']; + const paypalButtonLocations = ['product', 'cart', 'checkout', 'mini-cart', 'general']; paypalButtonLocations.forEach((location) => { const inputNamePrefix = location === 'checkout' ? '#ppcp-button' : '#ppcp-button_' + location; From da07c3b5fa1caca0f17ea5e0c06695de38c454f2 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 5 Dec 2022 16:53:30 +0400 Subject: [PATCH 03/17] Refactor smart button with new settings --- .../ppcp-button/src/Assets/SmartButton.php | 69 ++++++------------- .../src/Helper/SettingsStatus.php | 16 +++++ 2 files changed, 36 insertions(+), 49 deletions(-) diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index a7237c4f0..eae827c46 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -406,11 +406,9 @@ class SmartButton implements SmartButtonInterface { */ private function render_button_wrapper_registrar(): bool { - $not_enabled_on_product_page = $this->settings->has( 'button_single_product_enabled' ) && - ! $this->settings->get( 'button_single_product_enabled' ); if ( ( is_product() || wc_post_content_has_shortcode( 'product_page' ) ) - && ! $not_enabled_on_product_page + && $this->settings_status->is_smart_button_enabled_for_location( 'product' ) // TODO: it seems like there is no easy way to properly handle vaulted PayPal free trial, // so disable the buttons for now everywhere except checkout for free trial. && ! $this->is_free_trial_product() @@ -435,10 +433,8 @@ class SmartButton implements SmartButtonInterface { ); } - $not_enabled_on_minicart = $this->settings->has( 'button_mini_cart_enabled' ) && - ! $this->settings->get( 'button_mini_cart_enabled' ); if ( - ! $not_enabled_on_minicart + $this->settings_status->is_smart_button_enabled_for_location( 'mini-cart' ) && ! $this->is_free_trial_cart() ) { add_action( @@ -479,12 +475,11 @@ class SmartButton implements SmartButtonInterface { } ); - $not_enabled_on_cart = $this->settings->has( 'button_cart_enabled' ) && - ! $this->settings->get( 'button_cart_enabled' ); + $enabled_on_cart = $this->settings_status->is_smart_button_enabled_for_location( 'cart' ); add_action( $this->proceed_to_checkout_button_renderer_hook(), - function() use ( $not_enabled_on_cart ) { - if ( ! is_cart() || $not_enabled_on_cart || $this->is_free_trial_cart() || $this->is_cart_price_total_zero() ) { + function() use ( $enabled_on_cart ) { + if ( ! is_cart() || ! $enabled_on_cart || $this->is_free_trial_cart() || $this->is_cart_price_total_zero() ) { return; } @@ -868,8 +863,8 @@ class SmartButton implements SmartButtonInterface { 'shipping_field' => _x( 'Shipping %s', 'checkout-validation', 'woocommerce' ), ), 'order_id' => 'pay-now' === $this->context() ? absint( $wp->query_vars['order-pay'] ) : 0, - 'single_product_buttons_enabled' => $this->settings->has( 'button_product_enabled' ) && $this->settings->get( 'button_product_enabled' ), - 'mini_cart_buttons_enabled' => $this->settings->has( 'button_mini-cart_enabled' ) && $this->settings->get( 'button_mini-cart_enabled' ), + 'single_product_buttons_enabled' => $this->settings_status->is_smart_button_enabled_for_location( 'product' ), + 'mini_cart_buttons_enabled' => $this->settings_status->is_smart_button_enabled_for_location( 'mini-cart' ), 'basic_checkout_validation_enabled' => $this->basic_checkout_validation_enabled, ); @@ -1050,45 +1045,21 @@ class SmartButton implements SmartButtonInterface { * @throws NotFoundException If a setting has not been found. */ private function load_button_component() : bool { - $load_buttons = false; - if ( - $this->context() === 'checkout' - && $this->settings->has( 'button_enabled' ) - && $this->settings->get( 'button_enabled' ) - ) { - $load_buttons = true; - } - if ( - $this->context() === 'product' - && ( - ( $this->settings->has( 'button_product_enabled' ) && $this->settings->get( 'button_product_enabled' ) ) || - ( $this->settings_status->is_pay_later_messaging_enabled_for_location( 'product' ) ) - ) - ) { - $load_buttons = true; - } - if ( - $this->settings->has( 'button_mini-cart_enabled' ) - && $this->settings->get( 'button_mini-cart_enabled' ) - ) { - $load_buttons = true; - } + $smart_button_enabled_for_current_location = $this->settings_status->is_smart_button_enabled_for_location( $this->context() ); + $smart_button_enabled_for_mini_cart = $this->settings_status->is_smart_button_enabled_for_location( 'mini-cart' ); + $messaging_enabled_for_current_location = $this->settings_status->is_pay_later_messaging_enabled_for_location( $this->context() ); - if ( - $this->context() === 'cart' - && ( - ( $this->settings->has( 'button_cart_enabled' ) && $this->settings->get( 'button_cart_enabled' ) ) || - ( $this->settings_status->is_pay_later_messaging_enabled_for_location( 'cart' ) ) - ) - ) { - $load_buttons = true; + switch ( $this->context() ) { + case 'checkout': + case 'cart': + return $smart_button_enabled_for_current_location || $messaging_enabled_for_current_location; + case 'product': + return $smart_button_enabled_for_current_location || $messaging_enabled_for_current_location || $smart_button_enabled_for_mini_cart; + case 'pay-now': + return true; + default: + return $smart_button_enabled_for_mini_cart; } - - if ( $this->context() === 'pay-now' ) { - $load_buttons = true; - } - - return $load_buttons; } /** diff --git a/modules/ppcp-wc-gateway/src/Helper/SettingsStatus.php b/modules/ppcp-wc-gateway/src/Helper/SettingsStatus.php index 52a3f4130..b6a4cb640 100644 --- a/modules/ppcp-wc-gateway/src/Helper/SettingsStatus.php +++ b/modules/ppcp-wc-gateway/src/Helper/SettingsStatus.php @@ -125,4 +125,20 @@ class SettingsStatus { return $context === 'product' ? $enabled_for_product || $enabled_for_mini_cart : $enabled_for_current_location; } + + /** + * Checks whether smart buttons are enabled for a given location. + * + * @param string $location The location. + * @return bool true if is enabled, otherwise false. + */ + public function is_smart_button_enabled_for_location( string $location ): bool { + $selected_locations = $this->settings->has( 'smart_button_locations' ) ? $this->settings->get( 'smart_button_locations' ) : array(); + + if ( empty( $selected_locations ) ) { + return false; + } + + return in_array( $location, $selected_locations, true ); + } } From 7f120720cc5e23a47d2f1cc57454beefc5ea69a0 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 5 Dec 2022 17:05:19 +0400 Subject: [PATCH 04/17] Refactor disable gateways with new settings --- modules/ppcp-wc-gateway/services.php | 28 ++----------------- .../src/Checkout/DisableGateways.php | 15 ++++++++-- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 0664e15a9..e708a1848 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -142,7 +142,8 @@ return array( 'wcgateway.disabler' => static function ( ContainerInterface $container ): DisableGateways { $session_handler = $container->get( 'session.handler' ); $settings = $container->get( 'wcgateway.settings' ); - return new DisableGateways( $session_handler, $settings ); + $settings_status = $container->get( 'wcgateway.settings.status' ); + return new DisableGateways( $session_handler, $settings, $settings_status ); }, 'wcgateway.is-wc-payments-page' => static function ( ContainerInterface $container ): bool { @@ -1279,32 +1280,9 @@ return array( return array_keys( $container->get( 'wcgateway.settings.pay-later.messaging-locations' ) ); }, 'wcgateway.settings.pay-later.button-locations' => static function( ContainerInterface $container ): array { - $button_locations = array(); - $settings = $container->get( 'wcgateway.settings' ); assert( $settings instanceof Settings ); - $is_product_buttons_enabled = $settings->has( 'button_product_enabled' ) && $settings->get( 'button_product_enabled' ); - $is_mini_cart_buttons_enabled = $settings->has( 'button_mini-cart_enabled' ) && $settings->get( 'button_mini-cart_enabled' ); - $is_cart_buttons_enabled = $settings->has( 'button_cart_enabled' ) && $settings->get( 'button_cart_enabled' ); - $is_checkout_buttons_enabled = $settings->has( 'button_enabled' ) && $settings->get( 'button_enabled' ); - - if ( $is_product_buttons_enabled ) { - $button_locations['product'] = 'Single Product'; - } - - if ( $is_mini_cart_buttons_enabled ) { - $button_locations['mini-cart'] = 'Mini Cart'; - } - - if ( $is_cart_buttons_enabled ) { - $button_locations['cart'] = 'Cart'; - } - - if ( $is_checkout_buttons_enabled ) { - $button_locations['checkout'] = 'Checkout'; - } - - return $button_locations; + return $this->settings->has( 'smart_button_locations' ) ? $this->settings->get( 'smart_button_locations' ) : array(); }, ); diff --git a/modules/ppcp-wc-gateway/src/Checkout/DisableGateways.php b/modules/ppcp-wc-gateway/src/Checkout/DisableGateways.php index 5adce70ae..ad60cb9fb 100644 --- a/modules/ppcp-wc-gateway/src/Checkout/DisableGateways.php +++ b/modules/ppcp-wc-gateway/src/Checkout/DisableGateways.php @@ -14,6 +14,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; +use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus; /** * Class DisableGateways @@ -34,19 +35,29 @@ class DisableGateways { */ private $settings; + /** + * The Settings status helper. + * + * @var SettingsStatus + */ + protected $settings_status; + /** * DisableGateways constructor. * * @param SessionHandler $session_handler The Session Handler. * @param ContainerInterface $settings The Settings. + * @param SettingsStatus $settings_status The Settings status helper. */ public function __construct( SessionHandler $session_handler, - ContainerInterface $settings + ContainerInterface $settings, + SettingsStatus $settings_status ) { $this->session_handler = $session_handler; $this->settings = $settings; + $this->settings_status = $settings_status; } /** @@ -71,7 +82,7 @@ class DisableGateways { unset( $methods[ CreditCardGateway::ID ] ); } - if ( $this->settings->has( 'button_enabled' ) && ! $this->settings->get( 'button_enabled' ) && ! $this->session_handler->order() && is_checkout() ) { + if ( ! $this->settings_status->is_smart_button_enabled_for_location( 'checkout' ) && ! $this->session_handler->order() && is_checkout() ) { unset( $methods[ PayPalGateway::ID ] ); } From 2205b1bc1efca4d72d26b041086ff26586af0cd9 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 5 Dec 2022 17:12:30 +0400 Subject: [PATCH 05/17] Refactor default settings to match new settings --- modules/ppcp-wc-gateway/services.php | 8 ++++---- .../ppcp-wc-gateway/src/Settings/Settings.php | 19 ++++++++----------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index e708a1848..f4102eb97 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -142,7 +142,7 @@ return array( 'wcgateway.disabler' => static function ( ContainerInterface $container ): DisableGateways { $session_handler = $container->get( 'session.handler' ); $settings = $container->get( 'wcgateway.settings' ); - $settings_status = $container->get( 'wcgateway.settings.status' ); + $settings_status = $container->get( 'wcgateway.settings.status' ); return new DisableGateways( $session_handler, $settings, $settings_status ); }, @@ -195,8 +195,8 @@ return array( }, 'wcgateway.settings' => static function ( ContainerInterface $container ): Settings { - $messaging_locations = $container->get( 'wcgateway.settings.pay-later.messaging-locations' ); - return new Settings( array_keys( $messaging_locations ) ); + $default_button_locations = $container->get( 'wcgateway.button.default-locations' ); + return new Settings( $default_button_locations ); }, 'wcgateway.notice.connect' => static function ( ContainerInterface $container ): ConnectAdminNotice { $state = $container->get( 'onboarding.state' ); @@ -1283,6 +1283,6 @@ return array( $settings = $container->get( 'wcgateway.settings' ); assert( $settings instanceof Settings ); - return $this->settings->has( 'smart_button_locations' ) ? $this->settings->get( 'smart_button_locations' ) : array(); + return $settings->has( 'smart_button_locations' ) ? $settings->get( 'smart_button_locations' ) : array(); }, ); diff --git a/modules/ppcp-wc-gateway/src/Settings/Settings.php b/modules/ppcp-wc-gateway/src/Settings/Settings.php index 7ea6970fe..34b9718a9 100644 --- a/modules/ppcp-wc-gateway/src/Settings/Settings.php +++ b/modules/ppcp-wc-gateway/src/Settings/Settings.php @@ -29,19 +29,19 @@ class Settings implements ContainerInterface { private $settings = array(); /** - * The list of pay later selected default locations. + * The list of selected default button locations. * * @var string[] */ - protected $pay_later_default_locations; + protected $default_button_locations; /** * Settings constructor. * - * @param string[] $pay_later_default_locations The list of pay later selected default locations. + * @param string[] $default_button_locations The list of selected default button locations. */ - public function __construct( array $pay_later_default_locations ) { - $this->pay_later_default_locations = $pay_later_default_locations; + public function __construct( array $default_button_locations ) { + $this->default_button_locations = $default_button_locations; } /** @@ -109,14 +109,11 @@ class Settings implements ContainerInterface { 'Pay via PayPal.', 'woocommerce-paypal-payments' ), - 'button_product_enabled' => true, - 'button_mini-cart_enabled' => false, - 'button_cart_enabled' => true, + 'smart_button_locations' => $this->default_button_locations, 'pay_later_messaging_enabled' => true, - 'button_enabled' => true, 'pay_later_button_enabled' => true, - 'pay_later_button_locations' => $this->pay_later_default_locations, - 'pay_later_messaging_locations' => $this->pay_later_default_locations, + 'pay_later_button_locations' => $this->default_button_locations, + 'pay_later_messaging_locations' => $this->default_button_locations, 'brand_name' => get_bloginfo( 'name' ), 'dcc_gateway_title' => __( 'Credit Cards', 'woocommerce-paypal-payments' ), 'dcc_gateway_description' => __( From 3398e463296346834a0afff1daf279e640064a89 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 5 Dec 2022 18:12:15 +0400 Subject: [PATCH 06/17] Allow general/default styling for smart buttons --- modules/ppcp-button/src/Assets/SmartButton.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index eae827c46..265178906 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -1149,6 +1149,11 @@ class SmartButton implements SmartButtonInterface { 'tagline' => true, ); + $enable_styling_per_location = $this->settings->has( 'smart_button_enable_styling_per_location' ) && $this->settings->get( 'smart_button_enable_styling_per_location' ); + if ( ! $enable_styling_per_location ) { + $context = 'general'; + } + $value = isset( $defaults[ $style ] ) ? $defaults[ $style ] : ''; $value = $this->settings->has( 'button_' . $style ) ? From 108275b9b030178c859a9792e737b09c4178f741 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 5 Dec 2022 18:30:41 +0400 Subject: [PATCH 07/17] Create migration from old settings --- modules/ppcp-compat/src/CompatModule.php | 55 +++++++++++++++++++----- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/modules/ppcp-compat/src/CompatModule.php b/modules/ppcp-compat/src/CompatModule.php index 748a7ca63..505db4e6b 100644 --- a/modules/ppcp-compat/src/CompatModule.php +++ b/modules/ppcp-compat/src/CompatModule.php @@ -56,6 +56,7 @@ class CompatModule implements ModuleInterface { add_action( 'admin_enqueue_scripts', array( $asset_loader, 'enqueue' ) ); $this->migrate_pay_later_settings( $c ); + $this->migrate_smart_button_settings( $c ); } /** @@ -206,19 +207,19 @@ class CompatModule implements ModuleInterface { $disable_funding = $settings->has( 'disable_funding' ) ? $settings->get( 'disable_funding' ) : array(); $available_messaging_locations = array_keys( $c->get( 'wcgateway.settings.pay-later.messaging-locations' ) ); - $available_button_locations = array_merge( $available_messaging_locations, array( 'mini-cart' ) ); + $available_button_locations = array_keys( $c->get( 'wcgateway.button.locations' ) ); if ( in_array( 'credit', $disable_funding, true ) ) { $settings->set( 'pay_later_button_enabled', false ); } else { $settings->set( 'pay_later_button_enabled', true ); - $selected_button_locations = $this->pay_later_selected_locations( $settings, $available_button_locations, 'button' ); + $selected_button_locations = $this->selected_locations( $settings, $available_button_locations, 'button' ); if ( ! empty( $selected_button_locations ) ) { $settings->set( 'pay_later_button_locations', $selected_button_locations ); } } - $selected_messaging_locations = $this->pay_later_selected_locations( $settings, $available_messaging_locations, 'message' ); + $selected_messaging_locations = $this->selected_locations( $settings, $available_messaging_locations, 'message' ); if ( ! empty( $selected_messaging_locations ) ) { $settings->set( 'pay_later_messaging_enabled', true ); @@ -266,26 +267,58 @@ class CompatModule implements ModuleInterface { } /** - * Finds from old settings the locations, which should be selected for new Pay Later tab settings. + * Finds from old settings the selected locations for given type. * * @param Settings $settings The settings. * @param string[] $all_locations The list of all available locations. - * @param string $setting The setting: 'button' or 'message'. + * @param string $type The setting type: 'button' or 'message'. * @return string[] The list of locations, which should be selected. - * @throws NotFoundException When setting was not found. */ - protected function pay_later_selected_locations( Settings $settings, array $all_locations, string $setting ): array { - $pay_later_locations = array(); + protected function selected_locations( Settings $settings, array $all_locations, string $type ): array { + $button_locations = array(); foreach ( $all_locations as $location ) { $location_setting_name_part = $location === 'checkout' ? '' : "_{$location}"; - $setting_name = "{$setting}{$location_setting_name_part}_enabled"; + $setting_name = "{$type}{$location_setting_name_part}_enabled"; if ( $settings->has( $setting_name ) && $settings->get( $setting_name ) ) { - $pay_later_locations[] = $location; + $button_locations[] = $location; } } - return $pay_later_locations; + return $button_locations; + } + + /** + * Migrates the old smart button settings. + * + * The migration will be done on plugin upgrade if it hasn't already done. + * + * @param ContainerInterface $c The Container. + */ + protected function migrate_smart_button_settings( ContainerInterface $c ): void { + $is_smart_button_settings_migrated_option_name = 'woocommerce_ppcp-is_smart_button_settings_migrated'; + $is_smart_button_settings_migrated = get_option( $is_smart_button_settings_migrated_option_name ); + + if ( $is_smart_button_settings_migrated ) { + return; + } + + add_action( + 'woocommerce_paypal_payments_gateway_migrate_on_update', + function () use ( $c, $is_smart_button_settings_migrated_option_name ) { + $settings = $c->get( 'wcgateway.settings' ); + assert( $settings instanceof Settings ); + + $available_button_locations = array_keys( $c->get( 'wcgateway.button.locations' ) ); + $selected_button_locations = $this->selected_locations( $settings, $available_button_locations, 'button' ); + if ( ! empty( $selected_button_locations ) ) { + $settings->set( 'smart_button_locations', $selected_button_locations ); + $settings->persist(); + } + + update_option( $is_smart_button_settings_migrated_option_name, true ); + } + ); } } From 927f96f4dc5bdb7507ce85a865bdb808d6449eb3 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Tue, 6 Dec 2022 15:28:41 +0400 Subject: [PATCH 08/17] Enable styling per location by default for smart buttons --- .../ppcp-wc-gateway/src/Settings/Settings.php | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Settings/Settings.php b/modules/ppcp-wc-gateway/src/Settings/Settings.php index 34b9718a9..aa0981a03 100644 --- a/modules/ppcp-wc-gateway/src/Settings/Settings.php +++ b/modules/ppcp-wc-gateway/src/Settings/Settings.php @@ -104,19 +104,20 @@ class Settings implements ContainerInterface { $this->settings = get_option( self::KEY, array() ); $defaults = array( - 'title' => __( 'PayPal', 'woocommerce-paypal-payments' ), - 'description' => __( + 'title' => __( 'PayPal', 'woocommerce-paypal-payments' ), + 'description' => __( 'Pay via PayPal.', 'woocommerce-paypal-payments' ), - 'smart_button_locations' => $this->default_button_locations, - 'pay_later_messaging_enabled' => true, - 'pay_later_button_enabled' => true, - 'pay_later_button_locations' => $this->default_button_locations, - 'pay_later_messaging_locations' => $this->default_button_locations, - 'brand_name' => get_bloginfo( 'name' ), - 'dcc_gateway_title' => __( 'Credit Cards', 'woocommerce-paypal-payments' ), - 'dcc_gateway_description' => __( + 'smart_button_locations' => $this->default_button_locations, + 'smart_button_enable_styling_per_location' => true, + 'pay_later_messaging_enabled' => true, + 'pay_later_button_enabled' => true, + 'pay_later_button_locations' => $this->default_button_locations, + 'pay_later_messaging_locations' => $this->default_button_locations, + 'brand_name' => get_bloginfo( 'name' ), + 'dcc_gateway_title' => __( 'Credit Cards', 'woocommerce-paypal-payments' ), + 'dcc_gateway_description' => __( 'Pay with your credit card.', 'woocommerce-paypal-payments' ), From edfbf2308c03022ceb14a499672c70d5df3beb34 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Tue, 6 Dec 2022 15:53:52 +0400 Subject: [PATCH 09/17] Fix PHPcs problems --- .../Fields/paypal-smart-button-fields.php | 1407 +++++++++-------- 1 file changed, 705 insertions(+), 702 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php b/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php index 2903355b4..97bf6d285 100644 --- a/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php +++ b/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php @@ -26,719 +26,722 @@ return function ( ContainerInterface $container, array $fields ): array { $settings = $container->get( 'wcgateway.settings' ); assert( $settings instanceof Settings ); - $has_enabled_separate_button_gateways = $container->get( 'wcgateway.settings.has_enabled_separate_button_gateways' ); + $has_enabled_separate_button_gateways = $container->get( 'wcgateway.settings.has_enabled_separate_button_gateways' ); - $render_preview_element = function ( string $id ): string { - return ' + $render_preview_element = function ( string $id ): string { + return '

' . __( 'Preview', 'woocommerce-paypal-payments' ) . '

'; - }; + }; $smart_button_fields = array( - 'button_style_heading' => array( - 'heading' => __( 'PayPal Smart Buttons', 'woocommerce-paypal-payments' ), - 'type' => 'ppcp-heading', - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - 'description' => sprintf( - // translators: %1$s and %2$s are the opening and closing of HTML tag. - __( 'Customize the appearance of the PayPal smart buttons on the - %1$sCheckout page%5$s, %2$sSingle Product Page%5$s, %3$sCart page%5$s or on %4$sMini Cart page%5$s.', 'woocommerce-paypal-payments' ), - '', - '', - '', - '', - '' - ), - ), - 'smart_button_locations' => array( - 'title' => __( 'Smart Button Locations', 'woocommerce-paypal-payments' ), - 'type' => 'ppcp-multiselect', - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => $container->get( 'wcgateway.button.default-locations' ), - 'description' => __( 'Select where the PayPal smart buttons should be displayed.', 'woocommerce-paypal-payments' ), - 'options' => $container->get( 'wcgateway.button.locations' ), - 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'smart_button_enable_styling_per_location' => array( - 'title' => __( 'Customize Smart Buttons Per Location', 'woocommerce-paypal-payments' ), - 'type' => 'checkbox', - 'label' => __( 'Customize smart button style per location', 'woocommerce-paypal-payments' ), - 'default' => true, - 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - // General button styles. - 'button_general_layout' => array( - 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'classes' => $has_enabled_separate_button_gateways ? array( 'hide' ) : array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'vertical', - 'desc_tip' => true, - 'description' => __( - 'If additional funding sources are available to the buyer through PayPal, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), - 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_general_tagline' => array( - 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), - 'type' => 'checkbox', - 'default' => false, - 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), - 'desc_tip' => true, - 'description' => __( - 'Add the tagline. This line will only show up, if you select a horizontal layout.', - 'woocommerce-paypal-payments' - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_general_label' => array( - 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - /** - * Returns default label ID of the PayPal button. - */ - 'default' => apply_filters( 'woocommerce_paypal_payments_button_label_default', 'paypal' ), - 'desc_tip' => true, - 'description' => __( - 'This controls the label on the primary button.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), - 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), - 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), - 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_general_color' => array( - 'title' => __( 'Color', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'gold', - 'desc_tip' => true, - 'description' => __( - 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), - 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), - 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), - 'black' => __( 'Black', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_general_shape' => array( - 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'rect', - 'desc_tip' => true, - 'description' => __( - 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), - 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_general_preview' => array( - 'type' => 'ppcp-text', - 'text' => $render_preview_element( 'ppcpGeneralButtonPreview' ), - 'screens' => array( - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), + 'button_style_heading' => array( + 'heading' => __( 'PayPal Smart Buttons', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + 'description' => sprintf( + // translators: %1$s and %2$s are the opening and closing of HTML tag. + __( + 'Customize the appearance of the PayPal smart buttons on the + %1$sCheckout page%5$s, %2$sSingle Product Page%5$s, %3$sCart page%5$s or on %4$sMini Cart page%5$s.', + 'woocommerce-paypal-payments' + ), + '', + '', + '', + '', + '' + ), + ), + 'smart_button_locations' => array( + 'title' => __( 'Smart Button Locations', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-multiselect', + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => $container->get( 'wcgateway.button.default-locations' ), + 'description' => __( 'Select where the PayPal smart buttons should be displayed.', 'woocommerce-paypal-payments' ), + 'options' => $container->get( 'wcgateway.button.locations' ), + 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'smart_button_enable_styling_per_location' => array( + 'title' => __( 'Customize Smart Buttons Per Location', 'woocommerce-paypal-payments' ), + 'type' => 'checkbox', + 'label' => __( 'Customize smart button style per location', 'woocommerce-paypal-payments' ), + 'default' => true, + 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + // General button styles. + 'button_general_layout' => array( + 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'classes' => $has_enabled_separate_button_gateways ? array( 'hide' ) : array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'vertical', + 'desc_tip' => true, + 'description' => __( + 'If additional funding sources are available to the buyer through PayPal, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), + 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_general_tagline' => array( + 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), + 'type' => 'checkbox', + 'default' => false, + 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), + 'desc_tip' => true, + 'description' => __( + 'Add the tagline. This line will only show up, if you select a horizontal layout.', + 'woocommerce-paypal-payments' + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_general_label' => array( + 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + /** + * Returns default label ID of the PayPal button. + */ + 'default' => apply_filters( 'woocommerce_paypal_payments_button_label_default', 'paypal' ), + 'desc_tip' => true, + 'description' => __( + 'This controls the label on the primary button.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), + 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), + 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), + 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_general_color' => array( + 'title' => __( 'Color', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'gold', + 'desc_tip' => true, + 'description' => __( + 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), + 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), + 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), + 'black' => __( 'Black', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_general_shape' => array( + 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'rect', + 'desc_tip' => true, + 'description' => __( + 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), + 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_general_preview' => array( + 'type' => 'ppcp-text', + 'text' => $render_preview_element( 'ppcpGeneralButtonPreview' ), + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), - // Checkout page. - 'button_checkout_heading' => array( - 'heading' => __( 'Smart Buttons on checkout', 'woocommerce-paypal-payments' ), - 'type' => 'ppcp-heading', - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_layout' => array( - 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'classes' => $has_enabled_separate_button_gateways ? array( 'hide' ) : array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'vertical', - 'desc_tip' => true, - 'description' => __( - 'If additional funding sources are available to the buyer through PayPal, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), - 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_tagline' => array( - 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), - 'type' => 'checkbox', - 'default' => false, - 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), - 'desc_tip' => true, - 'description' => __( - 'Add the tagline. This line will only show up, if you select a horizontal layout.', - 'woocommerce-paypal-payments' - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_label' => array( - 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - /** - * Returns default label ID of the PayPal button. - */ - 'default' => apply_filters( 'woocommerce_paypal_payments_button_label_default', 'paypal' ), - 'desc_tip' => true, - 'description' => __( - 'This controls the label on the primary button.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), - 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), - 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), - 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_color' => array( - 'title' => __( 'Color', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'gold', - 'desc_tip' => true, - 'description' => __( - 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), - 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), - 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), - 'black' => __( 'Black', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_shape' => array( - 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'rect', - 'desc_tip' => true, - 'description' => __( - 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), - 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_preview' => array( - 'type' => 'ppcp-text', - 'text' => $render_preview_element( 'ppcpCheckoutButtonPreview' ), - 'screens' => array( - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), + // Checkout page. + 'button_checkout_heading' => array( + 'heading' => __( 'Smart Buttons on checkout', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_layout' => array( + 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'classes' => $has_enabled_separate_button_gateways ? array( 'hide' ) : array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'vertical', + 'desc_tip' => true, + 'description' => __( + 'If additional funding sources are available to the buyer through PayPal, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), + 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_tagline' => array( + 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), + 'type' => 'checkbox', + 'default' => false, + 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), + 'desc_tip' => true, + 'description' => __( + 'Add the tagline. This line will only show up, if you select a horizontal layout.', + 'woocommerce-paypal-payments' + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_label' => array( + 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + /** + * Returns default label ID of the PayPal button. + */ + 'default' => apply_filters( 'woocommerce_paypal_payments_button_label_default', 'paypal' ), + 'desc_tip' => true, + 'description' => __( + 'This controls the label on the primary button.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), + 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), + 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), + 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_color' => array( + 'title' => __( 'Color', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'gold', + 'desc_tip' => true, + 'description' => __( + 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), + 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), + 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), + 'black' => __( 'Black', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_shape' => array( + 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'rect', + 'desc_tip' => true, + 'description' => __( + 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), + 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_preview' => array( + 'type' => 'ppcp-text', + 'text' => $render_preview_element( 'ppcpCheckoutButtonPreview' ), + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), - // Single product page. - 'button_product_heading' => array( - 'heading' => __( 'Smart Buttons on Single Product', 'woocommerce-paypal-payments' ), - 'type' => 'ppcp-heading', - 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_product_layout' => array( - 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'horizontal', - 'desc_tip' => true, - 'description' => __( - 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), - 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_product_tagline' => array( - 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), - 'type' => 'checkbox', - 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), - 'default' => false, - 'desc_tip' => true, - 'description' => __( - 'Add the tagline. This line will only show up, if you select a horizontal layout.', - 'woocommerce-paypal-payments' - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_product_label' => array( - 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - /** - * Returns default label ID of the PayPal button on product pages. - */ - 'default' => apply_filters( 'woocommerce_paypal_payments_button_product_label_default', 'paypal' ), - 'desc_tip' => true, - 'description' => __( - 'This controls the label on the primary button.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), - 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), - 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), - 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_product_color' => array( - 'title' => __( 'Color', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'gold', - 'desc_tip' => true, - 'description' => __( - 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), - 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), - 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), - 'black' => __( 'Black', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_product_shape' => array( - 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'rect', - 'desc_tip' => true, - 'description' => __( - 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), - 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_product_preview' => array( - 'type' => 'ppcp-text', - 'text' => $render_preview_element( 'ppcpProductButtonPreview' ), - 'screens' => array( - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), + // Single product page. + 'button_product_heading' => array( + 'heading' => __( 'Smart Buttons on Single Product', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_layout' => array( + 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'horizontal', + 'desc_tip' => true, + 'description' => __( + 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), + 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_tagline' => array( + 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), + 'type' => 'checkbox', + 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), + 'default' => false, + 'desc_tip' => true, + 'description' => __( + 'Add the tagline. This line will only show up, if you select a horizontal layout.', + 'woocommerce-paypal-payments' + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_label' => array( + 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + /** + * Returns default label ID of the PayPal button on product pages. + */ + 'default' => apply_filters( 'woocommerce_paypal_payments_button_product_label_default', 'paypal' ), + 'desc_tip' => true, + 'description' => __( + 'This controls the label on the primary button.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), + 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), + 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), + 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_color' => array( + 'title' => __( 'Color', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'gold', + 'desc_tip' => true, + 'description' => __( + 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), + 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), + 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), + 'black' => __( 'Black', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_shape' => array( + 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'rect', + 'desc_tip' => true, + 'description' => __( + 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), + 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_preview' => array( + 'type' => 'ppcp-text', + 'text' => $render_preview_element( 'ppcpProductButtonPreview' ), + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), - // Cart settings. - 'button_cart_heading' => array( - 'heading' => __( 'Smart Buttons on Cart', 'woocommerce-paypal-payments' ), - 'type' => 'ppcp-heading', - 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_cart_layout' => array( - 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'horizontal', - 'desc_tip' => true, - 'description' => __( - 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), - 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_cart_tagline' => array( - 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), - 'type' => 'checkbox', - 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), - 'default' => false, - 'desc_tip' => true, - 'description' => __( - 'Add the tagline. This line will only show up, if you select a horizontal layout.', - 'woocommerce-paypal-payments' - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_cart_label' => array( - 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - /** - * Returns default label ID of the PayPal button in cart. - */ - 'default' => apply_filters( 'woocommerce_paypal_payments_button_cart_label_default', 'paypal' ), - 'desc_tip' => true, - 'description' => __( - 'This controls the label on the primary button.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), - 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), - 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), - 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_cart_color' => array( - 'title' => __( 'Color', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'gold', - 'desc_tip' => true, - 'description' => __( - 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), - 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), - 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), - 'black' => __( 'Black', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_cart_shape' => array( - 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'rect', - 'desc_tip' => true, - 'description' => __( - 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), - 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_cart_preview' => array( - 'type' => 'ppcp-text', - 'text' => $render_preview_element( 'ppcpCartButtonPreview' ), - 'screens' => array( - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), + // Cart settings. + 'button_cart_heading' => array( + 'heading' => __( 'Smart Buttons on Cart', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_layout' => array( + 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'horizontal', + 'desc_tip' => true, + 'description' => __( + 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), + 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_tagline' => array( + 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), + 'type' => 'checkbox', + 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), + 'default' => false, + 'desc_tip' => true, + 'description' => __( + 'Add the tagline. This line will only show up, if you select a horizontal layout.', + 'woocommerce-paypal-payments' + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_label' => array( + 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + /** + * Returns default label ID of the PayPal button in cart. + */ + 'default' => apply_filters( 'woocommerce_paypal_payments_button_cart_label_default', 'paypal' ), + 'desc_tip' => true, + 'description' => __( + 'This controls the label on the primary button.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), + 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), + 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), + 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_color' => array( + 'title' => __( 'Color', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'gold', + 'desc_tip' => true, + 'description' => __( + 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), + 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), + 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), + 'black' => __( 'Black', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_shape' => array( + 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'rect', + 'desc_tip' => true, + 'description' => __( + 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), + 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_preview' => array( + 'type' => 'ppcp-text', + 'text' => $render_preview_element( 'ppcpCartButtonPreview' ), + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), - // Mini cart settings. - 'button_mini-cart_heading' => array( - 'heading' => __( 'Smart Buttons on Mini Cart', 'woocommerce-paypal-payments' ), - 'type' => 'ppcp-heading', - 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_mini-cart_layout' => array( - 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'vertical', - 'desc_tip' => true, - 'description' => __( - 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), - 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_mini-cart_tagline' => array( - 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), - 'type' => 'checkbox', - 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), - 'default' => false, - 'desc_tip' => true, - 'description' => __( - 'Add the tagline. This line will only show up, if you select a horizontal layout.', - 'woocommerce-paypal-payments' - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_mini-cart_label' => array( - 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - /** - * Returns default label ID of the PayPal button in mini cart. - */ - 'default' => apply_filters( 'woocommerce_paypal_payments_button_mini_cart_label_default', 'paypal' ), - 'desc_tip' => true, - 'description' => __( - 'This controls the label on the primary button.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), - 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), - 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), - 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_mini-cart_color' => array( - 'title' => __( 'Color', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'gold', - 'desc_tip' => true, - 'description' => __( - 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), - 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), - 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), - 'black' => __( 'Black', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_mini-cart_shape' => array( - 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), - 'type' => 'select', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'rect', - 'desc_tip' => true, - 'description' => __( - 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', - 'woocommerce-paypal-payments' - ), - 'options' => array( - 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), - 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), - ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_mini-cart_height' => array( - 'title' => __( 'Button Height', 'woocommerce-paypal-payments' ), - 'type' => 'number', - 'default' => '35', - 'custom_attributes' => array( - 'min' => 25, - 'max' => 55, - ), - 'desc_tip' => true, - 'description' => __( 'Add a value from 25 to 55.', 'woocommerce-paypal-payments' ), - 'screens' => array( - State::STATE_START, - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), - 'button_mini-cart_preview' => array( - 'type' => 'ppcp-text', - 'text' => $render_preview_element( 'ppcpMiniCartButtonPreview' ), - 'screens' => array( - State::STATE_ONBOARDED, - ), - 'requirements' => array(), - 'gateway' => 'paypal', - ), + // Mini cart settings. + 'button_mini-cart_heading' => array( + 'heading' => __( 'Smart Buttons on Mini Cart', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_layout' => array( + 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'vertical', + 'desc_tip' => true, + 'description' => __( + 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'vertical' => __( 'Vertical', 'woocommerce-paypal-payments' ), + 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_tagline' => array( + 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), + 'type' => 'checkbox', + 'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ), + 'default' => false, + 'desc_tip' => true, + 'description' => __( + 'Add the tagline. This line will only show up, if you select a horizontal layout.', + 'woocommerce-paypal-payments' + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_label' => array( + 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + /** + * Returns default label ID of the PayPal button in mini cart. + */ + 'default' => apply_filters( 'woocommerce_paypal_payments_button_mini_cart_label_default', 'paypal' ), + 'desc_tip' => true, + 'description' => __( + 'This controls the label on the primary button.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'paypal' => __( 'PayPal', 'woocommerce-paypal-payments' ), + 'checkout' => __( 'Checkout', 'woocommerce-paypal-payments' ), + 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-payments' ), + 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_color' => array( + 'title' => __( 'Color', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'gold', + 'desc_tip' => true, + 'description' => __( + 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-payments' ), + 'blue' => __( 'Blue', 'woocommerce-paypal-payments' ), + 'silver' => __( 'Silver', 'woocommerce-paypal-payments' ), + 'black' => __( 'Black', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_shape' => array( + 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'rect', + 'desc_tip' => true, + 'description' => __( + 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', + 'woocommerce-paypal-payments' + ), + 'options' => array( + 'pill' => __( 'Pill', 'woocommerce-paypal-payments' ), + 'rect' => __( 'Rectangle', 'woocommerce-paypal-payments' ), + ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_height' => array( + 'title' => __( 'Button Height', 'woocommerce-paypal-payments' ), + 'type' => 'number', + 'default' => '35', + 'custom_attributes' => array( + 'min' => 25, + 'max' => 55, + ), + 'desc_tip' => true, + 'description' => __( 'Add a value from 25 to 55.', 'woocommerce-paypal-payments' ), + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_preview' => array( + 'type' => 'ppcp-text', + 'text' => $render_preview_element( 'ppcpMiniCartButtonPreview' ), + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), ); return array_merge( $fields, $smart_button_fields ); From 416881da7003c4acd45e0b6c96bb0367e8563f04 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 19 Dec 2022 20:23:09 +0400 Subject: [PATCH 10/17] Fix Pay later locations according to selected smart button locations --- modules/ppcp-wc-gateway/services.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index f4102eb97..dd433c034 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1283,6 +1283,24 @@ return array( $settings = $container->get( 'wcgateway.settings' ); assert( $settings instanceof Settings ); - return $settings->has( 'smart_button_locations' ) ? $settings->get( 'smart_button_locations' ) : array(); + $button_locations = $container->get( 'wcgateway.button.locations' ); + unset( $button_locations['mini-cart'] ); + + $smart_button_selected_locations = $settings->has( 'smart_button_locations' ) ? $settings->get( 'smart_button_locations' ) : array(); + $pay_later_button_locations = array(); + + if ( empty( $smart_button_selected_locations ) ) { + return $pay_later_button_locations; + } + + foreach ( $button_locations as $location_key => $location ) { + if ( ! in_array( $location_key, $smart_button_selected_locations, true ) ) { + continue; + } + + $pay_later_button_locations[ $location_key ] = $location; + } + + return $pay_later_button_locations; }, ); From c45a54aa68ff60ff88b72a9b9a80bf5eede08996 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Tue, 20 Dec 2022 19:08:17 +0400 Subject: [PATCH 11/17] Improve the conditional showing fields functionality --- .../ppcp-onboarding/resources/js/settings.js | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/modules/ppcp-onboarding/resources/js/settings.js b/modules/ppcp-onboarding/resources/js/settings.js index d9078660a..fb8e2e4e3 100644 --- a/modules/ppcp-onboarding/resources/js/settings.js +++ b/modules/ppcp-onboarding/resources/js/settings.js @@ -177,12 +177,21 @@ document.addEventListener( const payLaterMessagingEnabled = document.querySelector(payLaterMessagingEnabledSelector); const stylingPerElement = document.querySelector(stylingPerSelector); const locationsElement = document.querySelector(locationsSelector); + const stylingPerElementWrapper = stylingPerElement?.closest('tr'); + const stylingPerElementWrapperSelector = '#'+ stylingPerElementWrapper?.getAttribute('id'); if (! stylingPerElement) { return; } const toggleElementsBySelectedLocations = () => { + stylingPerElementWrapper.style.display = ''; + let selectedLocations = getSelectedLocations(locationsSelector); + + if(selectedLocations.length === 0) { + hideElements(groupToHideOnChecked.concat(stylingPerElementWrapperSelector)); + } + if (! stylingPerElement.checked) { return; } @@ -191,9 +200,6 @@ document.addEventListener( return; } - let checkedLocations = document.querySelectorAll(locationsSelector + ' :checked'); - const selectedLocations = [...checkedLocations].map(option => option.value); - const inputSelectors = inputSelectorsByLocations(selectedLocations, inputType); groupToShowOnChecked.forEach( (element) => { @@ -238,7 +244,11 @@ document.addEventListener( return; } - showElements(groupToHideOnChecked); + let selectedLocations = getSelectedLocations(locationsSelector); + if(selectedLocations.length > 0) { + showElements(groupToHideOnChecked); + } + if (inputType === 'messages') { togglePayLaterMessageFields(); } @@ -246,7 +256,15 @@ document.addEventListener( ); // We need to use jQuery here as the select might be a select2 element, which doesn't use native events. - jQuery(locationsElement).on('change', toggleElementsBySelectedLocations); + jQuery(locationsElement).on('change', function (){ + toggleElementsBySelectedLocations() + stylingPerElement.dispatchEvent(new Event('change')) + }); + } + + const getSelectedLocations = (selector) => { + let checkedLocations = document.querySelectorAll(selector + ' :checked'); + return [...checkedLocations].map(option => option.value); } const inputSelectorsByLocations = (locations, inputType = 'messages') => { @@ -311,15 +329,16 @@ document.addEventListener( const payLaterMessagingEnabled = document.querySelector(payLaterMessagingEnabledSelector); const stylingPerMessagingElement = document.querySelector('#ppcp-pay_later_enable_styling_per_messaging_location'); - if (! payLaterMessagingEnabled) { - return; - } - groupToggle( payLaterMessagingEnabledSelector, allPayLaterMessaginginputSelectors() ); + if (! payLaterMessagingEnabled) { + return; + + } + payLaterMessagingEnabled.addEventListener( 'change', (event) => { @@ -339,8 +358,6 @@ document.addEventListener( ['#field-pay_later_button_locations'] ); - toggleMessagingEnabled(); - toggleInputsBySelectedLocations( '#ppcp-pay_later_enable_styling_per_messaging_location', payLaterMessagingLocationsSelect, @@ -357,6 +374,8 @@ document.addEventListener( 'buttons' ); + toggleMessagingEnabled(); + groupToggle( '#ppcp-vault_enabled', From c54c42a46d543010a3db10b5b5b0437b92f32f8f Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Tue, 20 Dec 2022 19:24:58 +0400 Subject: [PATCH 12/17] Fix preview overlapping --- .../ppcp-wc-gateway/resources/css/gateway-settings.scss | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/modules/ppcp-wc-gateway/resources/css/gateway-settings.scss b/modules/ppcp-wc-gateway/resources/css/gateway-settings.scss index 744a0a307..0a4dc45cc 100644 --- a/modules/ppcp-wc-gateway/resources/css/gateway-settings.scss +++ b/modules/ppcp-wc-gateway/resources/css/gateway-settings.scss @@ -12,7 +12,7 @@ @media (min-width: 1200px) { float: right; - margin-top: -400px; + margin-top: -300px; } @media (min-width: 1400px) { @@ -29,12 +29,6 @@ } } -.ppcp-message-preview { - @media (min-width: 1200px) { - margin-top: -300px; - } -} - .ppcp-button-preview.pay-later { @media (min-width: 1200px) { margin-top: -250px; From 5b15b4b3fe4c7180c876bc71c2d171b4f8e53595 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 21 Dec 2022 17:08:56 +0400 Subject: [PATCH 13/17] Conditionally add a message when no location is selected. --- modules/ppcp-onboarding/resources/js/settings.js | 6 ++++++ .../ppcp-onboarding/src/Assets/OnboardingAssets.php | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/modules/ppcp-onboarding/resources/js/settings.js b/modules/ppcp-onboarding/resources/js/settings.js index fb8e2e4e3..41610cb90 100644 --- a/modules/ppcp-onboarding/resources/js/settings.js +++ b/modules/ppcp-onboarding/resources/js/settings.js @@ -187,9 +187,13 @@ document.addEventListener( const toggleElementsBySelectedLocations = () => { stylingPerElementWrapper.style.display = ''; let selectedLocations = getSelectedLocations(locationsSelector); + let emptySmartButtonLocationMessage = jQuery('.ppcp-empty-smart-button-location'); if(selectedLocations.length === 0) { hideElements(groupToHideOnChecked.concat(stylingPerElementWrapperSelector)); + if (emptySmartButtonLocationMessage.length === 0) { + jQuery(PayPalCommerceGatewaySettings.empty_smart_button_location_message).insertAfter(jQuery(smartButtonLocationsSelector).find('.description')); + } } if (! stylingPerElement.checked) { @@ -257,6 +261,8 @@ document.addEventListener( // We need to use jQuery here as the select might be a select2 element, which doesn't use native events. jQuery(locationsElement).on('change', function (){ + let emptySmartButtonLocationMessage = jQuery('.ppcp-empty-smart-button-location'); + emptySmartButtonLocationMessage?.remove(); toggleElementsBySelectedLocations() stylingPerElement.dispatchEvent(new Event('change')) }); diff --git a/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php b/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php index b28c1a254..7d57da2d5 100644 --- a/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php +++ b/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php @@ -110,6 +110,16 @@ class OnboardingAssets { $this->version, true ); + wp_localize_script( + 'ppcp-settings', + 'PayPalCommerceGatewaySettings', + array( + 'empty_smart_button_location_message' => sprintf( + '

%1$s

', + __( 'Note: If no button location is selected, the PayPal gateway will not be available.', 'woocommerce-paypal-payments' ) + ), + ) + ); $url = untrailingslashit( $this->module_url ) . '/assets/js/onboarding.js'; wp_register_script( From 0763e73cdbcb2573620603320b6c1e0a274d0047 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 21 Dec 2022 17:11:49 +0400 Subject: [PATCH 14/17] Rename the Enable/Disable setting label for PayPal Gateway --- modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php index 93528007a..944d7b67b 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php @@ -270,7 +270,7 @@ class PayPalGateway extends \WC_Payment_Gateway { 'type' => 'checkbox', 'desc_tip' => true, 'description' => __( 'In order to use PayPal or Advanced Card Processing, you need to enable the Gateway.', 'woocommerce-paypal-payments' ), - 'label' => __( 'Enable the PayPal Gateway', 'woocommerce-paypal-payments' ), + 'label' => __( 'Enable PayPal features for your store', 'woocommerce-paypal-payments' ), 'default' => 'no', ), 'ppcp' => array( From 6e5af8f0ab6ffbf443d6685f942c085301049f37 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 21 Dec 2022 18:01:19 +0400 Subject: [PATCH 15/17] Change the script localize name --- modules/ppcp-onboarding/resources/js/settings.js | 2 +- modules/ppcp-onboarding/src/Assets/OnboardingAssets.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-onboarding/resources/js/settings.js b/modules/ppcp-onboarding/resources/js/settings.js index 41610cb90..2eaad8ed2 100644 --- a/modules/ppcp-onboarding/resources/js/settings.js +++ b/modules/ppcp-onboarding/resources/js/settings.js @@ -192,7 +192,7 @@ document.addEventListener( if(selectedLocations.length === 0) { hideElements(groupToHideOnChecked.concat(stylingPerElementWrapperSelector)); if (emptySmartButtonLocationMessage.length === 0) { - jQuery(PayPalCommerceGatewaySettings.empty_smart_button_location_message).insertAfter(jQuery(smartButtonLocationsSelector).find('.description')); + jQuery(PayPalCommerceSettings.empty_smart_button_location_message).insertAfter(jQuery(smartButtonLocationsSelector).find('.description')); } } diff --git a/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php b/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php index 7d57da2d5..5cac972dc 100644 --- a/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php +++ b/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php @@ -112,7 +112,7 @@ class OnboardingAssets { ); wp_localize_script( 'ppcp-settings', - 'PayPalCommerceGatewaySettings', + 'PayPalCommerceSettings', array( 'empty_smart_button_location_message' => sprintf( '

%1$s

', From 851ded90213e2a038489bf1587d8f3d5097831d8 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 21 Dec 2022 18:20:42 +0400 Subject: [PATCH 16/17] Fix the descriptions and labels --- .../Fields/paypal-smart-button-fields.php | 46 +++++++++++++++++-- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php b/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php index 97bf6d285..edc49289f 100644 --- a/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php +++ b/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php @@ -50,7 +50,7 @@ return function ( ContainerInterface $container, array $fields ): array { // translators: %1$s and %2$s are the opening and closing of HTML tag. __( 'Customize the appearance of the PayPal smart buttons on the - %1$sCheckout page%5$s, %2$sSingle Product Page%5$s, %3$sCart page%5$s or on %4$sMini Cart page%5$s.', + %1$sCheckout page%5$s, %2$sSingle Product Page%5$s, %3$sCart page%5$s or on %4$sMini Cart%5$s.', 'woocommerce-paypal-payments' ), '', @@ -205,7 +205,16 @@ return function ( ContainerInterface $container, array $fields ): array { // Checkout page. 'button_checkout_heading' => array( - 'heading' => __( 'Smart Buttons on checkout', 'woocommerce-paypal-payments' ), + 'heading' => __( 'Checkout Buttons', 'woocommerce-paypal-payments' ), + 'description' => sprintf( + // translators: %1$s and %2$s are the opening and closing of HTML tag. + __( + 'Customize the appearance of the PayPal smart buttons on the %1$sCheckout page%2$s.', + 'woocommerce-paypal-payments' + ), + '', + '' + ), 'type' => 'ppcp-heading', 'screens' => array( State::STATE_START, @@ -338,7 +347,16 @@ return function ( ContainerInterface $container, array $fields ): array { // Single product page. 'button_product_heading' => array( - 'heading' => __( 'Smart Buttons on Single Product', 'woocommerce-paypal-payments' ), + 'heading' => __( 'Single Product Page Buttons', 'woocommerce-paypal-payments' ), + 'description' => sprintf( + // translators: %1$s and %2$s are the opening and closing of HTML tag. + __( + 'Customize the appearance of the PayPal smart buttons on the %1$sSingle Product Page%2$s.', + 'woocommerce-paypal-payments' + ), + '', + '' + ), 'type' => 'ppcp-heading', 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), 'requirements' => array(), @@ -468,7 +486,16 @@ return function ( ContainerInterface $container, array $fields ): array { // Cart settings. 'button_cart_heading' => array( - 'heading' => __( 'Smart Buttons on Cart', 'woocommerce-paypal-payments' ), + 'heading' => __( 'Cart Buttons', 'woocommerce-paypal-payments' ), + 'description' => sprintf( + // translators: %1$s and %2$s are the opening and closing of HTML tag. + __( + 'Customize the appearance of the PayPal smart buttons on the %1$sCart page%2$s.', + 'woocommerce-paypal-payments' + ), + '', + '' + ), 'type' => 'ppcp-heading', 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), 'requirements' => array(), @@ -598,7 +625,16 @@ return function ( ContainerInterface $container, array $fields ): array { // Mini cart settings. 'button_mini-cart_heading' => array( - 'heading' => __( 'Smart Buttons on Mini Cart', 'woocommerce-paypal-payments' ), + 'heading' => __( 'Mini Cart Buttons', 'woocommerce-paypal-payments' ), + 'description' => sprintf( + // translators: %1$s and %2$s are the opening and closing of HTML tag. + __( + 'Customize the appearance of the PayPal smart buttons on the %1$sMini Cart%2$s.', + 'woocommerce-paypal-payments' + ), + '', + '' + ), 'type' => 'ppcp-heading', 'screens' => array( State::STATE_START, State::STATE_ONBOARDED ), 'requirements' => array(), From 552dbe4751e7399d17739676e98571171c499a0a Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Fri, 23 Dec 2022 12:41:46 +0400 Subject: [PATCH 17/17] Improve the Checkout buttons description --- .../src/Settings/Fields/paypal-smart-button-fields.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php b/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php index edc49289f..2fb1ea5a6 100644 --- a/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php +++ b/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php @@ -209,11 +209,14 @@ return function ( ContainerInterface $container, array $fields ): array { 'description' => sprintf( // translators: %1$s and %2$s are the opening and closing of HTML tag. __( - 'Customize the appearance of the PayPal smart buttons on the %1$sCheckout page%2$s.', + 'Customize the appearance of the PayPal smart buttons on the %1$sCheckout page%2$s. + %3$sCheckout Buttons must be enabled to display the PayPal gateway on the Checkout page. + ', 'woocommerce-paypal-payments' ), '', - '' + '', + '' ), 'type' => 'ppcp-heading', 'screens' => array(