Whether you use WooCommerce for quotation purposes or just like to change the text; “Place order” works but sounds a bit flat and generic. Changing it to another text is very easy using a code snippet, as I will show in this blog post.

Changing the Order Confirmation Button

Using the following code snippet you can change the order confirmation button. You can change the “Confirm purchase” text to any of your likings.

<?php // For implementation instructions see: https://aceplugins.com/how-to-add-a-code-snippet/
/**
* Change the order confirmation button text.
*/
function ace_change_place_order_button_text( $text ) {
return 'Confirm purchase';
}
add_filter( 'woocommerce_order_button_text', 'ace_change_place_order_button_text' );

Custom Order Confirmation Button for User Roles

If you’d like to customize the order button for different user roles the following code snippet can be used. I’ve included 2 different texts for in total of 3 different user roles (so you can see how to change it for multiple roles at once too), and a fallback text.

<?php // For implementation instructions see: https://aceplugins.com/how-to-add-a-code-snippet/
/**
* Change the order confirmation button text per user role(s).
*/
function ace_change_place_order_button_text__user_role( $text ) {
$current_user = wp_get_current_user();
if ( in_array( 'administrator', $current_user->roles ) ) {
return 'Go ahead, place your test order, admin.';
}
if ( array_intersect( array( 'wholesale', 'warehouse' ), $current_user->roles ) ) {
return 'Get your quotation';
}
return 'Confirm purchase'; // User doesn't have any of the user roles that get a custom text
}
add_filter( 'woocommerce_order_button_text', 'ace_change_place_order_button_text__user_role', 11 );

Custom Order Confirmation Button Based on Cart Contents

How about if you sell subscriptions, memberships, cooled products? There are better alternatives to the default confirmation button text. This example shows 3 different confirmation button texts based on the product type, category and shipping class.

<?php // For implementation instructions see: https://aceplugins.com/how-to-add-a-code-snippet/
/**
* Change the order confirmation button text (cart contents).
*/
function ace_change_place_order_button_text__cart_contents( $text ) {
$cart_items = WC()->cart->get_cart_contents();
$cart_products = array_column( $cart_items, 'data' );
// Based on product types
$cart_product_types = array_map( function( $product ) { return $product->get_type(); }, $cart_products );
if ( in_array( 'subscription', $cart_product_types ) ) {
return 'Subscribe!';
}
// Based on cart categories
$cart_categories = array_map( function( $product ) { return wp_get_post_terms( $product->get_id(), 'product_cat' ); }, $cart_products );
$cart_categories = call_user_func_array('array_merge', $cart_categories );
if ( in_array( 'fruit', array_column( $cart_categories, 'slug' ) ) ) {
return 'Confirm your FRESH purchase!';
}
// Based on shipping class
$cart_classes = array_map( function( $product ) { return $product->get_shipping_class(); }, $cart_products );
if ( in_array( 'same-day-shipping', $cart_classes ) ) {
return 'Purchase now, shipped today!';
}
return 'Confirm purchase'; // User doesn't have any of the user roles that get a custom text
}
add_filter( 'woocommerce_order_button_text', 'ace_change_place_order_button_text__cart_contents', 11 );

About the author: Jeroen Sormani is actively building WordPress, WooCommerce and Easy Digital Downloads plugins. Slightly obsessed by writing high quality code.
Follow Jeroen on Twitter

Leave a Reply

Your email address will not be published. Required fields are marked *