From f535e70cb116332e237f563b7108df6363169a1f Mon Sep 17 00:00:00 2001 From: Alex P Date: Tue, 31 Oct 2023 11:42:35 +0200 Subject: [PATCH] Move messages via js on pay order page --- .../ppcp-button/src/Assets/SmartButton.php | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index e47f76884..9210e6d58 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -395,7 +395,9 @@ class SmartButton implements SmartButtonInterface { return false; } - $get_hook = function ( string $location ): ?array { + $default_pay_order_hook = 'woocommerce_pay_order_before_submit'; + + $get_hook = function ( string $location ) use ( $default_pay_order_hook ): ?array { switch ( $location ) { case 'checkout': return $this->messages_renderer_hook( $location, 'woocommerce_review_order_before_payment', 10 ); @@ -425,6 +427,28 @@ class SmartButton implements SmartButtonInterface { $hook['priority'] ); + // Looks like there are no hooks like woocommerce_review_order_before_payment on the pay for order page, so have to move using JS. + if ( $location === 'pay-now' && $hook['name'] === $default_pay_order_hook && + /** + * The filter returning true if Pay Later messages should be displayed before payment methods + * on the pay for order page, like in checkout. + */ + apply_filters( + 'woocommerce_paypal_payments_put_pay_order_messages_before_payment_methods', + true + ) + ) { + add_action( + 'ppcp_after_pay_order_message_wrapper', + function () { + echo ' +'; + } + ); + } + return true; }