Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Change Specific Payment Gateway Title in WooCommerce?

As an online store owner, you would have accommodated your site that offers both online and offline payment options. However, providing the appropriate label for such payment methods is equally important as it ensures clarity about the payment method your customers choose. 

Especially, this is useful when your customers would like to go cardless, and in such cases, you can provide the titles such as ‘Pay later’ or ‘Invoice Payments’, etc. Another scenario where such requirements are needed is for locality-based customers. For eg, a German-based customer will not understand the term “Bank transfer” who are used to the right German name “BankĂĽberweisung”. In such cases, you can replace the default WooCommerce payment method names and provide an apt title that best suits your business needs.

This post will help you to change specific payment gateway title in WooCommerce.

Where to Add Custom Code in WooCommerce?

It is advisable to add the code snippets to the functions.php file of your child theme. Access the file directly from Appearance->Theme File Editor->Locating the child theme’s functions.php from the right sidebar. You can also access it from your theme’s directory file. Insert the following code snippet in functions.php. The alternative & easy option is to install & activate the Code Snippets plugin. You can then add the code as a new snippet via the plugin.

Preliminary Steps

Find and replace the payment method ID that you wish to modify in the script given below.

How to find Payment Method IDs

  • Go to the admin area of your WooCommerce site.
  • In the left menu, click on “WooCommerce” and then choose “Settings.”
  • Navigate to the “Payments” tab.
  • You’ll see a list of all payment gateways set up for your store.
  • Hover over any of the payment method links.
  • Look at the link that appears at the bottom left of the screen.
  • Find the payment method ID in the text following “section=”.
How to find Payment Method IDs

Solution: Change Specific Payment Gateway Title in WooCommerce

Imagine you run an online store that offers a unique service where customers are manually invoiced for their purchases. In this scenario, you might not want to stick with the generic payment method label provided by WooCommerce, such as “Check” or “Bank Transfer.” The below code snippet will help you to change the title and its description as per your choice.

// Add filters to modify the title and description of a WooCommerce payment gateway
add_filter('woocommerce_gateway_title', 'change_payment_gateway_title', 100, 2);
add_filter('woocommerce_gateway_description', 'change_payment_gateway_description', 25, 2);
// Custom function to change the title of the Cheque payment gateway
function change_payment_gateway_title($title, $payment_id) {
    // Check if the payment gateway ID is 'cheque'
    if ($payment_id === 'cheque') {
        // If 'cheque', change the title to "Something else"
        $title = __("Invoice Payments", "woocommerce");
    }
    // Return the modified or unchanged title
    return $title;
}
// Custom function to change the description of the BACS payment gateway
function change_payment_gateway_description($description, $gateway_id) {
    // Check if the payment gateway ID is 'cheque'
    if ('cheque' === $gateway_id) {
        // If 'cheque', change the description to custom text with HTML tags
        $description = 'Flexible Payment, without risk';
    }
    // Return the modified or unchanged description
    return $description;
}

Output

The below output shows that the default payment gateway title “Check Payments” has been changed to “Invoice Payments,” and the description has also been updated.

How to Change Specific Payment Gateway Title in WooCommerce?

Code Explanation

Modify the title of a WooCommerce payment gateway

  • The filter hook woocommerce_gateway_title is employed to target the modification of payment gateway titles.
  • The function change_cheque_payment_gateway_title is associated with this filter hook.
  • The function receives two parameters: $title (the current title of the payment gateway) and $payment_id (the identifier of the payment method).
  • Inside the function, there’s a conditional check. If the payment method ID is ‘cheque’, the title is updated to “Invoice Payments” using the __() function for localization.
  • The modified or unchanged title is then returned.

Modify the description of a WooCommerce payment gateway

  • The filter hook woocommerce_gateway_description is used to target the modification of payment gateway descriptions.
  • The function change_payment_gateway_description is associated with this filter hook.
  • The function receives two parameters: $description (the current description of the payment gateway) and $gateway_id (the identifier of the payment method).
  • Inside the function, there’s a conditional check. If the payment method ID is ‘cheque’, the description is updated to ‘Flexible Payment, without risk’.
  • The modified or unchanged description is then returned.

Conclusion

The above code helps to change the payment gateway title using the Payment Gateway ID. As an admin, you would require the IDs of the payment methods for many more customizations on your site. In such cases, you can also get the ID of a Payment Method in WooCommerce that is displayed only for admins and shop managers on the checkout page.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x