I need to change the order_button_text
for a specific payment gateway (COD in this case).
I could only get it to change globally (for all payment gate
You can do it like this:
add_filter( 'woocommerce_available_payment_gateways', 'woocommerce_available_payment_gateways' );
function woocommerce_available_payment_gateways( $available_gateways ) {
if (! is_checkout() ) return $available_gateways; // stop doing anything if we're not on checkout page.
if (array_key_exists('paypal',$available_gateways)) {
// Gateway ID for Paypal is 'paypal'.
$available_gateways['paypal']->order_button_text = __( 'Request a Quote', 'woocommerce' );
}
return $available_gateways;
}
This code example is for paypal. For reference of the gateway IDs, please check WooCoomerce > Settings > Checkout > Gateway display order
I have two option for payments on my website. Cash or Card Payment
I'm trying to change the text of the Place order button on woocommerce.
If payment method is cash i want the button to say "Confirm"
If payment method is card i want the button to say "Confirm & pay"
Im using the follwing to chnage the text to Confirm but need some help to add the extra condition depending on payment method:
add_filter( 'woocommerce_order_button_text', 'woo_custom_order_button_text' );
function woo_custom_order_button_text() {
return __( 'Confirm', 'woocommerce' );
}
Here it is the clean way to do it, using woocommerce_review_order_before_payment
action hook with a custom function hooked in, using mainly jQuery (because it's a client side live event):
add_action( 'woocommerce_review_order_before_payment', 'customizing_checkout_button', 10, 0 );
function customizing_checkout_button(){
$text1 = __( 'Place order', 'woocommerce' );
$text2 = __( 'Request a Quote', 'woocommerce' );
?>
<script>
jQuery(function($){
// 1. Initialising once loaded
if($('input[name^="payment_method"]:checked').val() == 'cod' )
$('input[name^="woocommerce_checkout_place_order"]').val('<?php echo $text2; ?>');
else
$('input[name^="woocommerce_checkout_place_order"]').val('<?php echo $text1; ?>');
// 2. Live event detection:When payment method is changed
$( 'form.checkout' ).on( 'change', 'input[name^="payment_method"]', function() {
var choosenPaymentMethod = $('input[name^="payment_method"]:checked').val(); // Chosen
if( choosenPaymentMethod == 'cod' )
$('input[name^="woocommerce_checkout_place_order"]').val('<?php echo $text2; ?>');
else
$('input[name^="woocommerce_checkout_place_order"]').val('<?php echo $text1; ?>');
});
});
</script>
<?php
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works with WooCommerce 3+
Easy solution, try to add the following code in your theme's function.php
file.
/**
* @snippet Change checkout order button text
* @package WooCommerce
*/
function change_checkout_order_button_text() {
return __( 'Complete Order', 'woocommerce' );
}
add_filter( 'woocommerce_order_button_text', 'change_checkout_order_button_text' );