58
We’ve already seen how to rename the “Place Order” button on the WooCommerce Checkout page, but today I want to find a way to rename it dynamically and conditionally i.e. based on the payment gateway that is selected while checking out.
The snippet requires the payment gateway “ID” – here’s a quick tut in case you don’t know how to retrieve that: How to Find WooCommerce Payment Gateway ID
Other than that, it’s pretty simple logic. Enjoy!
PHP Snippet: Rename “Place Order” Button Dynamically Based on Selected Payment Gateway @ WooCommerce Checkout
/**
* @snippet Rename "Place Order" By Gateway @ WooCommerce Checkout
* @how-to Get tutoraspire.com FREE
* @author Tutor Aspire
* @compatible WooCommerce 6
* @donate $9 https://tutoraspire.com
*/
add_filter( 'woocommerce_available_payment_gateways', 'tutoraspire_rename_place_order_button' );
function tutoraspire_rename_place_order_button( $gateways ) {
if ( $gateways['bacs'] ) {
$gateways['bacs']->order_button_text = 'View Bank Details';
} elseif ( $gateways['cod'] ) {
$gateways['cod']->order_button_text = 'Confirm Cash on Delivery';
}
return $gateways;
}