mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
Merge pull request #2153 from woocommerce/PCP-2794-add-pay-later-messaging-to-block-cart-checkout
Refactor the Pay Later Messaging block and add dedicated Cart/Checkout blocks (2794)
This commit is contained in:
commit
e0afc257b9
42 changed files with 4323 additions and 272 deletions
|
@ -34,6 +34,7 @@ use WooCommerce\PayPalCommerce\Button\Helper\ContextTrait;
|
|||
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\PayLaterBlock\PayLaterBlockModule;
|
||||
use WooCommerce\PayPalCommerce\PayLaterWCBlocks\PayLaterWCBlocksModule;
|
||||
use WooCommerce\PayPalCommerce\SavePaymentMethods\Endpoint\CreatePaymentToken;
|
||||
use WooCommerce\PayPalCommerce\SavePaymentMethods\Endpoint\CreateSetupToken;
|
||||
use WooCommerce\PayPalCommerce\SavePaymentMethods\Endpoint\CreatePaymentTokenForGuest;
|
||||
|
@ -438,7 +439,20 @@ class SmartButton implements SmartButtonInterface {
|
|||
wp_is_block_theme()
|
||||
);
|
||||
|
||||
$get_hook = function ( string $location ) use ( $default_pay_order_hook, $is_block_theme ): ?array {
|
||||
$has_paylater_block =
|
||||
(
|
||||
PayLaterBlockModule::is_block_enabled( $this->settings_status ) &&
|
||||
has_block( 'woocommerce-paypal-payments/paylater-messages' )
|
||||
) ||
|
||||
(
|
||||
PayLaterWCBlocksModule::is_block_enabled( $this->settings_status, $location ) &&
|
||||
(
|
||||
has_block( 'woocommerce-paypal-payments/checkout-paylater-messages' ) ||
|
||||
has_block( 'woocommerce-paypal-payments/cart-paylater-messages' )
|
||||
)
|
||||
);
|
||||
|
||||
$get_hook = function ( string $location ) use ( $default_pay_order_hook, $is_block_theme, $has_paylater_block ): ?array {
|
||||
switch ( $location ) {
|
||||
case 'checkout':
|
||||
return $this->messages_renderer_hook( $location, 'woocommerce_review_order_before_payment', 10 );
|
||||
|
@ -457,11 +471,14 @@ class SmartButton implements SmartButtonInterface {
|
|||
? $this->messages_renderer_block( $location, 'core/navigation', 10 )
|
||||
: $this->messages_renderer_hook( $location, 'loop_start', 20 );
|
||||
default:
|
||||
return null;
|
||||
return $has_paylater_block
|
||||
? $this->messages_renderer_hook( $location, 'ppcp_paylater_message_block', 10 )
|
||||
: null;
|
||||
}
|
||||
};
|
||||
|
||||
$hook = $get_hook( $location );
|
||||
|
||||
if ( ! $hook ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -492,7 +509,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
function () {
|
||||
echo '
|
||||
<script>
|
||||
document.querySelector("#payment").before(document.querySelector("#ppcp-messages"))
|
||||
document.querySelector("#payment").before(document.querySelector(".ppcp-messages"))
|
||||
</script>';
|
||||
}
|
||||
);
|
||||
|
@ -601,10 +618,6 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
|
|||
return false;
|
||||
}
|
||||
|
||||
if ( in_array( $this->context(), array( 'checkout-block', 'cart-block' ), true ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->should_load_buttons() || $this->should_load_messages() || $this->can_render_dcc();
|
||||
}
|
||||
|
||||
|
@ -655,7 +668,11 @@ 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_block_enabled( $this->settings_status );
|
||||
$has_paylater_block = PayLaterBlockModule::is_block_enabled( $this->settings_status ) && has_block( 'woocommerce-paypal-payments/paylater-messages' );
|
||||
|
||||
if ( 'cart-block' === $location || 'checkout-block' === $location ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch ( $location ) {
|
||||
case 'checkout':
|
||||
|
@ -667,9 +684,6 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
|
|||
return $messaging_enabled_for_current_location;
|
||||
case 'block-editor':
|
||||
return true;
|
||||
case 'checkout-block':
|
||||
case 'cart-block':
|
||||
return $has_paylater_block || $this->is_block_editor();
|
||||
default:
|
||||
return $has_paylater_block;
|
||||
}
|
||||
|
@ -789,7 +803,7 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
|
|||
*/
|
||||
do_action( "ppcp_before_{$location_hook}_message_wrapper" );
|
||||
|
||||
$messages_placeholder = '<div id="ppcp-messages" data-partner-attribution-id="Woo_PPCP"></div>';
|
||||
$messages_placeholder = '<div class="ppcp-messages" data-partner-attribution-id="Woo_PPCP"></div>';
|
||||
|
||||
if ( is_array( $block_params ) && ( $block_params['blockName'] ?? false ) ) {
|
||||
$this->render_after_block(
|
||||
|
@ -888,7 +902,20 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
|
|||
|
||||
$styling_per_location = $this->settings->has( 'pay_later_enable_styling_per_messaging_location' ) && $this->settings->get( 'pay_later_enable_styling_per_messaging_location' );
|
||||
$location = $styling_per_location ? $location : 'general';
|
||||
$setting_name_prefix = "pay_later_{$location}_message";
|
||||
|
||||
// Map checkout-block and cart-block message options to checkout and cart options.
|
||||
switch ( $location ) {
|
||||
case 'checkout-block':
|
||||
$location = 'checkout';
|
||||
break;
|
||||
case 'cart-block':
|
||||
$location = 'cart';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$setting_name_prefix = "pay_later_{$location}_message";
|
||||
|
||||
$layout = $this->settings->has( "{$setting_name_prefix}_layout" ) ? $this->settings->get( "{$setting_name_prefix}_layout" ) : 'text';
|
||||
$logo_type = $this->settings->has( "{$setting_name_prefix}_logo" ) ? $this->settings->get( "{$setting_name_prefix}_logo" ) : 'primary';
|
||||
|
@ -899,7 +926,7 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
|
|||
$text_size = $this->settings->has( "{$setting_name_prefix}_text_size" ) ? $this->settings->get( "{$setting_name_prefix}_text_size" ) : '12';
|
||||
|
||||
return array(
|
||||
'wrapper' => '#ppcp-messages',
|
||||
'wrapper' => '.ppcp-messages',
|
||||
'is_hidden' => ! $this->is_pay_later_filter_enabled_for_location( $this->context() ),
|
||||
'block' => array(
|
||||
'enabled' => PayLaterBlockModule::is_block_enabled( $this->settings_status ),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue