From bd9343c893a7d26faf6c5de954ccc49ff539fea3 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Mon, 14 Jul 2025 19:31:01 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20empty=20description=20?= =?UTF-8?q?handling=20and=20logo=20display=20for=20PayPal=20gateway?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Override `get_description()` to properly handle saved empty descriptions using `array_key_exists()` instead of `get_option()` fallbacks - Fix issue where empty descriptions reverted to defaults - Utilize the `woocommerce_paypal_payments_paypal_gateway_icon` filter to handle PayPal logo display correctly --- .../src/Endpoint/CreateOrderEndpoint.php | 4 ++-- .../Data/Definition/PaymentMethodsDefinition.php | 4 ++-- modules/ppcp-settings/src/SettingsModule.php | 11 +++++++++++ .../ppcp-wc-gateway/src/Gateway/PayPalGateway.php | 15 +++++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php b/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php index 8d7682be08..78ef86fd26 100644 --- a/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php +++ b/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php @@ -254,8 +254,8 @@ public function __construct( $this->pay_now_contexts = $pay_now_contexts; $this->handle_shipping_in_paypal = $handle_shipping_in_paypal; $this->server_side_shipping_callback_enabled = $server_side_shipping_callback_enabled; - $this->funding_sources_without_redirect = $funding_sources_without_redirect; - $this->logger = $logger; + $this->funding_sources_without_redirect = $funding_sources_without_redirect; + $this->logger = $logger; } /** diff --git a/modules/ppcp-settings/src/Data/Definition/PaymentMethodsDefinition.php b/modules/ppcp-settings/src/Data/Definition/PaymentMethodsDefinition.php index 456317f458..0feba26af8 100644 --- a/modules/ppcp-settings/src/Data/Definition/PaymentMethodsDefinition.php +++ b/modules/ppcp-settings/src/Data/Definition/PaymentMethodsDefinition.php @@ -136,7 +136,7 @@ private function build_method_definition( $gateway = $this->wc_gateways[ $gateway_id ] ?? null; $gateway_title = $gateway ? $gateway->get_title() : $title; - $gateway_description = $gateway ? $gateway->get_description() : $description; + $gateway_description = $gateway->settings['description'] ?? $description; $enabled = $this->settings->is_method_enabled( $gateway_id ); $config = array( 'id' => $gateway_id, @@ -159,7 +159,7 @@ private function build_method_definition( ), 'checkoutPageDescription' => array( 'type' => 'text', - 'default' => $gateway ? $gateway->get_description() : '', + 'default' => $gateway_description, 'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ), ), ), diff --git a/modules/ppcp-settings/src/SettingsModule.php b/modules/ppcp-settings/src/SettingsModule.php index 605b182f8b..d144b6bef1 100644 --- a/modules/ppcp-settings/src/SettingsModule.php +++ b/modules/ppcp-settings/src/SettingsModule.php @@ -527,6 +527,17 @@ function ( string $description, WC_Payment_Gateway $gateway ) { 2 ); + add_filter( + 'woocommerce_paypal_payments_paypal_gateway_icon', + function ( string $icon_url ) use ( $container ) { + $payment_settings = $container->get( 'settings.data.payment' ); + assert( $payment_settings instanceof PaymentSettings ); + + // If "Show logo" is disabled, return an empty string to hide the icon. + return $payment_settings->get_paypal_show_logo() ? $icon_url : ''; + } + ); + add_filter( 'woocommerce_paypal_payments_card_button_gateway_should_register_gateway', '__return_true' ); add_filter( diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php index 60a350c8b9..2c70c7baf8 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php @@ -351,6 +351,21 @@ public function get_title() { return parent::get_title(); } + /** + * Return the gateway's description. + * + * @return string + */ + public function get_description() { + $gateway_settings = get_option( $this->get_option_key(), array() ); + + if ( array_key_exists( 'description', $gateway_settings ) ) { + return $gateway_settings['description']; + } + + return $this->description; + } + /** * Whether the Gateway needs to be setup. * From 3ba91e8f443b82261fde6fc134a4c48ed191a5f3 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Mon, 14 Jul 2025 20:30:17 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20the=20empty=20descript?= =?UTF-8?q?ion=20for=20the=20block=20checkout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/ppcp-blocks/src/PayPalPaymentMethod.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-blocks/src/PayPalPaymentMethod.php b/modules/ppcp-blocks/src/PayPalPaymentMethod.php index e03bd57d35..b4c9705243 100644 --- a/modules/ppcp-blocks/src/PayPalPaymentMethod.php +++ b/modules/ppcp-blocks/src/PayPalPaymentMethod.php @@ -260,7 +260,7 @@ public function get_payment_method_data() { 'src' => $this->gateway->icon, ), ), - 'description' => $this->gateway->description, + 'description' => $this->gateway->get_description(), 'smartButtonsEnabled' => $smart_buttons_enabled, 'placeOrderEnabled' => $place_order_enabled, 'fundingSource' => $this->session_handler->funding_source(),