In many cases, we need to change different texts in WooCommerce. Especially different titles, add-to-cart buttons, and place order buttons.
Previous
Next
Today, we will know how to change the text of the place-order button on the checkout page according to the payment method selected. For this, we need to add a function in the
function.php
file. But for safety, we can also add PHP code using the WordPress plugin called “Code Snippets“.
<?php
add_filter( 'woocommerce_available_payment_gateways', 'bbloomer_rename_place_order_button' );
function bbloomer_rename_place_order_button( $gateways ) {
if ( $gateways['payoneer'] ) {
$gateways['payoneer']->order_button_text = 'Order Via Payoneer';
} if ( $gateways['bacs'] ) {
$gateways['bacs']->order_button_text = 'View Bank Details';
} if ( $gateways['woo_rocket'] ) {
$gateways['woo_rocket']->order_button_text = 'Order Via Rocket';
} if ( $gateways['woo_bkash'] ) {
$gateways['woo_bkash']->order_button_text = 'Order Via bKash';
}
return $gateways;
}
In the code shown above, “bacs” is WooCommerce’s default direct bank transfer id, and “cod” is the cash on delivery id. To know the id of any payment gateway, if you hover over the name of that gateway, you will find the id at the end of the URL shown in the bottom-left corner of the browser.
Note: If the above code doesn’t work then using “if” instead of “elseif” in php code will work. Contact us for any help.
Thanks for your blog, nice to read. Do not stop.
Thank you!