Home » WooCommerce: How to Remove “What is PayPal?” @ Checkout

WooCommerce: How to Remove “What is PayPal?” @ Checkout

by Tutor Aspire

One of my premium course students had an apparently simple requirement. Her client didn’t want to show the “What is PayPal?” text (and link) on the checkout page. In fact, why sending users away from the checkout? And who doesn’t know what PayPal is nowadays? Well, let’s see how this is done via a simple “filter” – but this time I’d like to show you a step-by-step tutorial! Let me know what you think about this in the comments 🙂

WooCommerce "What is PayPal" at checkout
WooCommerce “What is PayPal” at checkout

1. WooCommerce Plugin File Search

First, we try to find where this “What is PayPal” is generated from, usually a PHP function. In fact, this is what shows in the woocommerceincludesgatewayspaypalclass-wc-gateway-paypal.php file:

/**
 * Get gateway icon.
 * @return string
 */

public function get_icon() {
$icon_html = '';
$icon      = (array) $this->get_icon_image( WC()->countries->get_base_country() );

foreach ( $icon as $i ) {
$icon_html .= '' . esc_attr__( 'PayPal Acceptance Mark', 'woocommerce' ) . '';
}

$icon_html .= sprintf( '' . esc_attr__( 'What is PayPal?', 'woocommerce' ) . '', esc_url( $this->get_icon_url( WC()->countries->get_base_country() ) ) );

return apply_filters( 'woocommerce_gateway_icon', $icon_html, $this->id );
}

2. Boom! The function is “filterable”

WooCommerce gives us this, so that we can “filter” or “edit” the behavior of such function without having to override WooCommerce core files:

return apply_filters( 'woocommerce_gateway_icon', $icon_html, $this->id );

3. Let’s find the HTML code that we need to filter

Now that we know the function is editable via a hook (filter), we find out that the “What is PayPal” link is added by the variable $icon_html.

$icon_html .= sprintf( '' . esc_attr__( 'What is PayPal?', 'woocommerce' ) . '', esc_url( $this->get_icon_url( WC()->countries->get_base_country() ) ) );

Please note the “.=”: this means $icon_html is being concatenated to the previous $icon_html, which contains the PayPal image:

$icon_html .= '' . esc_attr__( 'PayPal Acceptance Mark', 'woocommerce' ) . '';

4. Let’s code the PHP snippet: How to Remove “What is PayPal?” @ Checkout

Now that we have all the information, let’s start coding. Take a look at the comments in the PHP snippet to see if you can follow me.

/**
 * @snippet       WooCommerce Remove "What is PayPal?" @ Checkout
 * @how-to        Get tutoraspire.com FREE
 * @sourcecode    https://tutoraspire.com/?p=21186
 * @author        Tutor Aspire
 * @compatible    WooCommerce 3.5.4
 * @donate $9     https://tutoraspire.com
 */

add_filter( 'woocommerce_gateway_icon', 'tutoraspire_remove_what_is_paypal', 10, 2 );

function tutoraspire_remove_what_is_paypal( $icon_html, $gateway_id ) {
if( 'paypal' == $gateway_id ) {
   $icon_html = 'PayPal Acceptance Mark';
}
return $icon_html;
}

5. Summary

To summarize:

1) I’m calling the filter with: add_filter( ‘woocommerce_gateway_icon’, …
2) I’m creating my custom override function ‘tutoraspire_remove_what_is_paypal’
3) I’m passing to the function two variables: the HTML ($icon_html) and the gateway name ($gateway_id), as we need to make sure we override those through the filter
4) I make sure this is the PayPal gateway with the if > then
5) I edit the $icon_html variable, by just saying “trash the previous, use mine instead”
6) I return $icon_html to the system

Let me know in the comments if this “extended” tutorial helps 🙂

You may also like