Simplify message wrapper rendering and add shop, home locations

This commit is contained in:
Alex P 2023-10-16 21:41:17 +03:00
parent 0062f20c7a
commit 7da5d8d68a
No known key found for this signature in database
GPG key ID: 54487A734A204D71
6 changed files with 328 additions and 45 deletions

View file

@ -274,7 +274,7 @@ document.addEventListener(
}, 1000));
loadPaypalScript(oldScriptSettings, () => {
const payLaterMessagingLocations = ['product', 'cart', 'checkout', 'general'];
const payLaterMessagingLocations = ['product', 'cart', 'checkout', 'shop', 'home', 'general'];
const paypalButtonLocations = ['product', 'cart', 'checkout', 'mini-cart', 'general'];
paypalButtonLocations.forEach((location) => {

View file

@ -1354,7 +1354,13 @@ return array(
'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;
return array_merge(
$button_locations,
array(
'shop' => __( 'Shop', 'woocommerce-paypal-payments' ),
'home' => __( 'Home', 'woocommerce-paypal-payments' ),
)
);
},
'wcgateway.button.default-locations' => static function( ContainerInterface $container ): array {
return array_keys( $container->get( 'wcgateway.settings.pay-later.messaging-locations' ) );

View file

@ -623,6 +623,254 @@ return function ( ContainerInterface $container, array $fields ): array {
'requirements' => array( 'messages' ),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
// Shop.
'pay_later_shop_messaging_heading' => array(
'heading' => __( 'Pay Later Messaging on the Shop page', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-heading',
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array(),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
'pay_later_shop_message_layout' => array(
'title' => __( 'Shop Messaging Layout', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'default' => 'text',
'desc_tip' => true,
'description' => __( 'The layout of the message.', 'woocommerce-paypal-payments' ),
'options' => array(
'text' => __( 'Text', 'woocommerce-paypal-payments' ),
'flex' => __( 'Banner', 'woocommerce-paypal-payments' ),
),
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array( 'messages' ),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
'pay_later_shop_message_logo' => array(
'title' => __( 'Shop Messaging Logo', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'default' => 'inline',
'desc_tip' => true,
'description' => __( 'What logo the text message contains. Only applicable, when the layout style Text is used.', 'woocommerce-paypal-payments' ),
'options' => array(
'primary' => __( 'Primary', 'woocommerce-paypal-payments' ),
'alternative' => __( 'Alternative', 'woocommerce-paypal-payments' ),
'inline' => __( 'Inline', 'woocommerce-paypal-payments' ),
'none' => __( 'None', 'woocommerce-paypal-payments' ),
),
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array( 'messages' ),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
'pay_later_shop_message_position' => array(
'title' => __( 'Shop Messaging Logo Position', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'default' => 'left',
'desc_tip' => true,
'description' => __( 'The position of the logo. Only applicable, when the layout style Text is used.', 'woocommerce-paypal-payments' ),
'options' => array(
'left' => __( 'Left', 'woocommerce-paypal-payments' ),
'right' => __( 'Right', 'woocommerce-paypal-payments' ),
'top' => __( 'Top', 'woocommerce-paypal-payments' ),
),
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array( 'messages' ),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
'pay_later_shop_message_color' => array(
'title' => __( 'Shop Messaging Text Color', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'default' => 'black',
'desc_tip' => true,
'description' => __( 'The color of the text. Only applicable, when the layout style Text is used.', 'woocommerce-paypal-payments' ),
'options' => array(
'black' => __( 'Black', 'woocommerce-paypal-payments' ),
'white' => __( 'White', 'woocommerce-paypal-payments' ),
'monochrome' => __( 'Monochrome', 'woocommerce-paypal-payments' ),
'grayscale' => __( 'Grayscale', 'woocommerce-paypal-payments' ),
),
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array( 'messages' ),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
'pay_later_shop_message_flex_color' => array(
'title' => __( 'Shop Messaging Color', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'default' => $default_messaging_flex_color,
'desc_tip' => true,
'description' => __( 'The color of the text. Only applicable, when the layout style Banner is used.', 'woocommerce-paypal-payments' ),
'options' => array(
'blue' => __( 'Blue', 'woocommerce-paypal-payments' ),
'black' => __( 'Black', 'woocommerce-paypal-payments' ),
'white' => __( 'White', 'woocommerce-paypal-payments' ),
'white-no-border' => __( 'White no border', 'woocommerce-paypal-payments' ),
'gray' => __( 'Gray', 'woocommerce-paypal-payments' ),
'monochrome' => __( 'Monochrome', 'woocommerce-paypal-payments' ),
'grayscale' => __( 'Grayscale', 'woocommerce-paypal-payments' ),
),
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array( 'messages' ),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
'pay_later_shop_message_flex_ratio' => array(
'title' => __( 'Shop Messaging Ratio', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'default' => '8x1',
'desc_tip' => true,
'description' => __( 'The width/height ratio of the banner. Only applicable, when the layout style Banner is used.', 'woocommerce-paypal-payments' ),
'options' => array(
'1x1' => __( '1x1', 'woocommerce-paypal-payments' ),
'1x4' => __( '1x4', 'woocommerce-paypal-payments' ),
'8x1' => __( '8x1', 'woocommerce-paypal-payments' ),
'20x1' => __( '20x1', 'woocommerce-paypal-payments' ),
),
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array( 'messages' ),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
'pay_later_shop_message_preview' => array(
'type' => 'ppcp-text',
'text' => $render_preview_element( 'ppcpShopMessagePreview', 'message', $messaging_message ),
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array( 'messages' ),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
// Home.
'pay_later_home_messaging_heading' => array(
'heading' => __( 'Pay Later Messaging on the Home page', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-heading',
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array(),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
'pay_later_home_message_layout' => array(
'title' => __( 'Home Messaging Layout', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'default' => 'text',
'desc_tip' => true,
'description' => __( 'The layout of the message.', 'woocommerce-paypal-payments' ),
'options' => array(
'text' => __( 'Text', 'woocommerce-paypal-payments' ),
'flex' => __( 'Banner', 'woocommerce-paypal-payments' ),
),
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array( 'messages' ),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
'pay_later_home_message_logo' => array(
'title' => __( 'Home Messaging Logo', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'default' => 'inline',
'desc_tip' => true,
'description' => __( 'What logo the text message contains. Only applicable, when the layout style Text is used.', 'woocommerce-paypal-payments' ),
'options' => array(
'primary' => __( 'Primary', 'woocommerce-paypal-payments' ),
'alternative' => __( 'Alternative', 'woocommerce-paypal-payments' ),
'inline' => __( 'Inline', 'woocommerce-paypal-payments' ),
'none' => __( 'None', 'woocommerce-paypal-payments' ),
),
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array( 'messages' ),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
'pay_later_home_message_position' => array(
'title' => __( 'Home Messaging Logo Position', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'default' => 'left',
'desc_tip' => true,
'description' => __( 'The position of the logo. Only applicable, when the layout style Text is used.', 'woocommerce-paypal-payments' ),
'options' => array(
'left' => __( 'Left', 'woocommerce-paypal-payments' ),
'right' => __( 'Right', 'woocommerce-paypal-payments' ),
'top' => __( 'Top', 'woocommerce-paypal-payments' ),
),
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array( 'messages' ),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
'pay_later_home_message_color' => array(
'title' => __( 'Home Messaging Text Color', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'default' => 'black',
'desc_tip' => true,
'description' => __( 'The color of the text. Only applicable, when the layout style Text is used.', 'woocommerce-paypal-payments' ),
'options' => array(
'black' => __( 'Black', 'woocommerce-paypal-payments' ),
'white' => __( 'White', 'woocommerce-paypal-payments' ),
'monochrome' => __( 'Monochrome', 'woocommerce-paypal-payments' ),
'grayscale' => __( 'Grayscale', 'woocommerce-paypal-payments' ),
),
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array( 'messages' ),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
'pay_later_home_message_flex_color' => array(
'title' => __( 'Home Messaging Color', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'default' => $default_messaging_flex_color,
'desc_tip' => true,
'description' => __( 'The color of the text. Only applicable, when the layout style Banner is used.', 'woocommerce-paypal-payments' ),
'options' => array(
'blue' => __( 'Blue', 'woocommerce-paypal-payments' ),
'black' => __( 'Black', 'woocommerce-paypal-payments' ),
'white' => __( 'White', 'woocommerce-paypal-payments' ),
'white-no-border' => __( 'White no border', 'woocommerce-paypal-payments' ),
'gray' => __( 'Gray', 'woocommerce-paypal-payments' ),
'monochrome' => __( 'Monochrome', 'woocommerce-paypal-payments' ),
'grayscale' => __( 'Grayscale', 'woocommerce-paypal-payments' ),
),
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array( 'messages' ),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
'pay_later_home_message_flex_ratio' => array(
'title' => __( 'Home Messaging Ratio', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'default' => '8x1',
'desc_tip' => true,
'description' => __( 'The width/height ratio of the banner. Only applicable, when the layout style Banner is used.', 'woocommerce-paypal-payments' ),
'options' => array(
'1x1' => __( '1x1', 'woocommerce-paypal-payments' ),
'1x4' => __( '1x4', 'woocommerce-paypal-payments' ),
'8x1' => __( '8x1', 'woocommerce-paypal-payments' ),
'20x1' => __( '20x1', 'woocommerce-paypal-payments' ),
),
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array( 'messages' ),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
'pay_later_home_message_preview' => array(
'type' => 'ppcp-text',
'text' => $render_preview_element( 'ppcpHomeMessagePreview', 'message', $messaging_message ),
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array( 'messages' ),
'gateway' => Settings::PAY_LATER_TAB_ID,
),
);
return array_merge( $fields, $pay_later_fields );