* * @psalm-suppress MissingClosureParamType */ function ($labels) { if (!is_array($labels)) { return $labels; } $labels['paypal'] = 'PayPal'; return $labels; } ); add_action('wp', function () use ($container) { global $wp; if (!isset($wp->query_vars['delete-payment-method'])) { return; } $token_id = absint($wp->query_vars['delete-payment-method']); $token = WC_Payment_Tokens::get($token_id); if (is_null($token) || $token->get_gateway_id() !== PayPalGateway::ID && $token->get_gateway_id() !== CreditCardGateway::ID) { return; } // phpcs:ignore WordPress.Security.NonceVerification $wpnonce = wc_clean(wp_unslash($_REQUEST['_wpnonce'] ?? '')); $token_id_string = (string) $token_id; $action = 'delete-payment-method-' . $token_id_string; if ($token->get_user_id() !== get_current_user_id() || !isset($wpnonce) || !is_string($wpnonce) || wp_verify_nonce($wpnonce, $action) === \false) { wc_add_notice(__('Invalid payment method.', 'woocommerce-paypal-payments'), 'error'); wp_safe_redirect(wc_get_account_endpoint_url('payment-methods')); exit; } try { do_action('woocommerce_paypal_payments_before_delete_payment_token', $token->get_token()); $payment_tokens_endpoint = $container->get('api.endpoint.payment-tokens'); $payment_tokens_endpoint->delete($token->get_token()); } catch (RuntimeException $exception) { wc_add_notice(__('Could not delete payment token. ', 'woocommerce-paypal-payments') . $exception->getMessage(), 'error'); return; } }); add_filter( 'woocommerce_available_payment_gateways', /** * Param types removed to avoid third-party issues. * * @psalm-suppress MissingClosureParamType */ function ($methods) { global $wp; if (!is_array($methods)) { return $methods; } if (isset($wp->query_vars['add-payment-method']) && apply_filters('woocommerce_paypal_payments_disable_add_payment_method', \true)) { unset($methods[PayPalGateway::ID]); } return $methods; } ); return \true; } }