Skip to content
Advertisement

Change specific payment gateway title in WooCommerce

I need to change the Woocommerce payment gateway names, not the ones hat are displayed on the frontend(this can easily be achieved in the settings) but the inernatl titles Woo is using.

In class-wc-gateway-cheque.php for example I found this

JavaScript

but simply changing the name there did not work. How can I change the name Woocommerce is using internally for this payment method?

Advertisement

Answer

So what you can do instead is to copy the source code from WC_Gateway_Cheque Class to a plugin file as explained below:

To make a custom gateway based on an existing WooCommerce payment method as cheque, It’s recommended to copy the source code from WC_Gateway_Cheque Class in a plugin (adapting the code for your needs).

You can copy the code to a php file that you will name for example wc-invoice-payments.php.

The code to copy:

JavaScript

Code goes in functions.php file of your active child theme (or active theme). Tested and works.

Then enable WooCommerce Invoice Gateway plugin in admin.
Now in WooCommerce settings, Payments section, you can enable this payment gateway.

You can unset / remove original Cheque payment gateway changing the 1st function like:

JavaScript

It should work as expected.

Related: Extending WooCommerce COD payment gateway in a plugin


Initial answer:

As all payment gateways extend WC_Payment_Gateway Class, if you look to get_title() method you will see that you can use the filter hook woocommerce_gateway_title.

So for "cheque" payment Id, you will use it as follow:

JavaScript

Code goes in functions.php file of your active child theme (or active theme). Tested and works.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement