diff --git a/modules.php b/modules.php
index 8ee91f43e..c6840d8ab 100644
--- a/modules.php
+++ b/modules.php
@@ -68,7 +68,7 @@ return function ( string $root_dir ): iterable {
$modules[] = ( require "$modules_dir/ppcp-save-payment-methods/module.php" )();
}
- if ( PayLaterBlockModule::is_enabled() ) {
+ if ( PayLaterBlockModule::is_module_loading_required() ) {
$modules[] = ( require "$modules_dir/ppcp-paylater-block/module.php" )();
}
diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php
index d63b56af4..12e7abfbd 100644
--- a/modules/ppcp-button/src/Assets/SmartButton.php
+++ b/modules/ppcp-button/src/Assets/SmartButton.php
@@ -631,7 +631,7 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
$messaging_enabled_for_current_location = $this->settings_status->is_pay_later_messaging_enabled_for_location( $location );
- $has_paylater_block = has_block( 'woocommerce-paypal-payments/paylater-messages' ) && PayLaterBlockModule::is_enabled();
+ $has_paylater_block = has_block( 'woocommerce-paypal-payments/paylater-messages' ) && PayLaterBlockModule::is_block_enabled( $this->settings_status );
switch ( $location ) {
case 'checkout':
@@ -878,7 +878,7 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
'wrapper' => '#ppcp-messages',
'is_hidden' => ! $this->is_pay_later_filter_enabled_for_location( $this->context() ),
'block' => array(
- 'enabled' => PayLaterBlockModule::is_enabled(),
+ 'enabled' => PayLaterBlockModule::is_block_enabled( $this->settings_status ),
),
'amount' => $amount,
'placement' => $placement,
diff --git a/modules/ppcp-paylater-block/resources/js/edit.js b/modules/ppcp-paylater-block/resources/js/edit.js
index 63330318c..291a8732c 100644
--- a/modules/ppcp-paylater-block/resources/js/edit.js
+++ b/modules/ppcp-paylater-block/resources/js/edit.js
@@ -34,7 +34,7 @@ export default function Edit( { attributes, clientId, setAttributes } ) {
};
let classes = ['ppcp-paylater-block-preview', 'ppcp-overlay-parent'];
- if (PcpPayLaterBlock.vaultingEnabled) {
+ if (PcpPayLaterBlock.vaultingEnabled || !PcpPayLaterBlock.placementEnabled) {
classes = ['ppcp-paylater-block-preview', 'ppcp-paylater-unavailable', 'block-editor-warning'];
}
const props = useBlockProps({className: classes});
@@ -68,6 +68,27 @@ export default function Edit( { attributes, clientId, setAttributes } ) {
}
+ if (!PcpPayLaterBlock.placementEnabled) {
+ return
+
+
{__('PayPal Pay Later Messaging', 'woocommerce-paypal-payments')}
+
{__('Pay Later Messaging cannot be used while the “WooCommerce Block” messaging placement is disabled. Enable the placement in the PayPal Payments Pay Later settings to reactivate this block.', 'woocommerce-paypal-payments')}
+
+
+
+ }
+
let scriptParams = useScriptParams(PcpPayLaterBlock.ajax.cart_script_params);
if (scriptParams === null) {
return loadingElement;
diff --git a/modules/ppcp-paylater-block/src/PayLaterBlockModule.php b/modules/ppcp-paylater-block/src/PayLaterBlockModule.php
index 9544c5686..d5953f407 100644
--- a/modules/ppcp-paylater-block/src/PayLaterBlockModule.php
+++ b/modules/ppcp-paylater-block/src/PayLaterBlockModule.php
@@ -15,6 +15,7 @@ use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
+use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
/**
@@ -22,16 +23,26 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
*/
class PayLaterBlockModule implements ModuleInterface {
/**
- * Returns whether the block should be loaded.
+ * Returns whether the block module should be loaded.
*/
- public static function is_enabled(): bool {
+ public static function is_module_loading_required(): bool {
return apply_filters(
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
'woocommerce.feature-flags.woocommerce_paypal_payments.paylater_block_enabled',
- getenv( 'PCP_PAYLATER_BLOCK' ) === '1'
+ getenv( 'PCP_PAYLATER_BLOCK' ) !== '0'
);
}
+ /**
+ * Returns whether the block is enabled.
+ *
+ * @param SettingsStatus $settings_status The Settings status helper.
+ * @return bool true if the block is enabled, otherwise false.
+ */
+ public static function is_block_enabled( SettingsStatus $settings_status ): bool {
+ return self::is_module_loading_required() && $settings_status->is_pay_later_messaging_enabled_for_location( 'product_preview' );
+ }
+
/**
* {@inheritDoc}
*/
@@ -71,13 +82,15 @@ class PayLaterBlockModule implements ModuleInterface {
$script_handle,
'PcpPayLaterBlock',
array(
- 'ajax' => array(
+ 'ajax' => array(
'cart_script_params' => array(
'endpoint' => \WC_AJAX::get_endpoint( CartScriptParamsEndpoint::ENDPOINT ),
),
),
- 'settingsUrl' => admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' ),
- 'vaultingEnabled' => $settings->has( 'vault_enabled' ) && $settings->get( 'vault_enabled' ),
+ 'settingsUrl' => admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' ),
+ 'vaultingEnabled' => $settings->has( 'vault_enabled' ) && $settings->get( 'vault_enabled' ),
+ 'placementEnabled' => self::is_block_enabled( $c->get( 'wcgateway.settings.status' ) ),
+ 'payLaterSettingsUrl' => admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&ppcp-tab=ppcp-pay-later' ),
)
);
diff --git a/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js b/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js
index 0d4cc3b79..8f2c24f8f 100644
--- a/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js
+++ b/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js
@@ -40,7 +40,7 @@ document.addEventListener( 'DOMContentLoaded', () => {
partnerClientId: PcpPayLaterConfigurator.partnerClientId,
partnerName: 'WooCommerce',
bnCode: 'Woo_PPCP',
- placements: ['cart', 'checkout', 'product', 'category', 'homepage', 'custom_placement'],
+ placements: ['cart', 'checkout', 'product', 'shop', 'home', 'product_preview'],
styleOverrides: {
button: publishButtonClassName,
header: PcpPayLaterConfigurator.headerClassName,
diff --git a/modules/ppcp-paylater-configurator/src/Endpoint/SaveConfig.php b/modules/ppcp-paylater-configurator/src/Endpoint/SaveConfig.php
index 051a89dd6..6584b7da3 100644
--- a/modules/ppcp-paylater-configurator/src/Endpoint/SaveConfig.php
+++ b/modules/ppcp-paylater-configurator/src/Endpoint/SaveConfig.php
@@ -101,12 +101,10 @@ class SaveConfig {
$enabled_locations = array();
foreach ( $config as $placement => $data ) {
- $location = $this->configurator_placement_to_location( $placement );
-
- $this->save_config_for_location( $data, $location );
+ $this->save_config_for_location( $data, $placement );
if ( $data['status'] === 'enabled' ) {
- $enabled_locations[] = $location;
+ $enabled_locations[] = $placement;
}
}
@@ -145,24 +143,4 @@ class SaveConfig {
$this->settings->set( $settings_key, $config[ $key ] );
}
}
-
- /**
- * Converts the configurator placement into location in the old settings.
- *
- * @param string $placement The configurator placement.
- */
- private function configurator_placement_to_location( string $placement ): string {
- switch ( $placement ) {
- case 'cart':
- case 'checkout':
- case 'product':
- return $placement;
- case 'category':
- return 'shop';
- case 'homepage':
- return 'home';
- default:
- return '';
- }
- }
}
diff --git a/modules/ppcp-paylater-configurator/src/Factory/ConfigFactory.php b/modules/ppcp-paylater-configurator/src/Factory/ConfigFactory.php
index cb272984d..240cfeafd 100644
--- a/modules/ppcp-paylater-configurator/src/Factory/ConfigFactory.php
+++ b/modules/ppcp-paylater-configurator/src/Factory/ConfigFactory.php
@@ -22,11 +22,12 @@ class ConfigFactory {
*/
public function from_settings( Settings $settings ): array {
return array(
- $this->location_to_configurator_placement( 'cart' ) => $this->for_location( $settings, 'cart' ),
- $this->location_to_configurator_placement( 'checkout' ) => $this->for_location( $settings, 'checkout' ),
- $this->location_to_configurator_placement( 'product' ) => $this->for_location( $settings, 'product' ),
- $this->location_to_configurator_placement( 'shop' ) => $this->for_location( $settings, 'shop' ),
- $this->location_to_configurator_placement( 'home' ) => $this->for_location( $settings, 'home' ),
+ 'cart' => $this->for_location( $settings, 'cart' ),
+ 'checkout' => $this->for_location( $settings, 'checkout' ),
+ 'product' => $this->for_location( $settings, 'product' ),
+ 'shop' => $this->for_location( $settings, 'shop' ),
+ 'home' => $this->for_location( $settings, 'home' ),
+ 'product_preview' => $this->for_location( $settings, 'product_preview' ),
);
}
@@ -39,8 +40,7 @@ class ConfigFactory {
private function for_location( Settings $settings, string $location ): array {
$selected_locations = $settings->has( 'pay_later_messaging_locations' ) ? $settings->get( 'pay_later_messaging_locations' ) : array();
- $placement = $this->location_to_configurator_placement( $location );
- if ( in_array( $placement, array( 'category', 'homepage' ), true ) ) {
+ if ( in_array( $location, array( 'shop', 'home' ), true ) ) {
$config = array(
'layout' => 'flex',
'color' => $this->get_or_default( $settings, "pay_later_{$location}_message_flex_color", 'black', array( 'black', 'blue', 'white', 'white-no-border' ) ),
@@ -60,32 +60,12 @@ class ConfigFactory {
return array_merge(
array(
'status' => in_array( $location, $selected_locations, true ) ? 'enabled' : 'disabled',
- 'placement' => $placement,
+ 'placement' => $location,
),
$config
);
}
- /**
- * Converts the location name from the old settings into the configurator placement.
- *
- * @param string $location The location name in the old settings.
- */
- private function location_to_configurator_placement( string $location ): string {
- switch ( $location ) {
- case 'cart':
- case 'checkout':
- case 'product':
- return $location;
- case 'shop':
- return 'category';
- case 'home':
- return 'homepage';
- default:
- return '';
- }
- }
-
/**
* Returns the settings value or default, if does not exist or not allowed value.
*
diff --git a/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php b/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php
index d3e110289..fd5d4c6d5 100644
--- a/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php
+++ b/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php
@@ -29,7 +29,7 @@ class PayLaterConfiguratorModule implements ModuleInterface {
return apply_filters(
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
'woocommerce.feature-flags.woocommerce_paypal_payments.paylater_configurator_enabled',
- getenv( 'PCP_PAYLATER_CONFIGURATOR' ) === '1'
+ getenv( 'PCP_PAYLATER_CONFIGURATOR' ) !== '0'
);
}
@@ -79,7 +79,7 @@ class PayLaterConfiguratorModule implements ModuleInterface {
static function () use ( $c, $settings ) {
wp_enqueue_script(
'ppcp-paylater-configurator-lib',
- 'https://www.paypalobjects.com/merchant-library/preview/merchant-configurator.js',
+ 'https://www.paypalobjects.com/merchant-library/merchant-configurator.js',
array(),
$c->get( 'ppcp.asset-version' ),
true