Skip to content

Fix empty description handling and logo display for PayPal gateway (4999) #3527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/ppcp-blocks/src/PayPalPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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' ),
),
),
Expand Down
11 changes: 11 additions & 0 deletions modules/ppcp-settings/src/SettingsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 15 additions & 0 deletions modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Loading