I want to add $order->get_total();
to my woocommerce place order button, on the checkout page. So I just want it to display the total as an string.
This is what I have in my functions.php, which is returning a blank.
add_filter( 'woocommerce_order_button_text', 'woo_custom_order_button_text' );
function woo_custom_order_button_text() {
return __( $order->get_total(), 'woocommerce' );
}
I have tried this as well:
function woo_custom_order_button_text() {
return __( $order_total, 'woocommerce' );
}
Both snippets returns a blank, nothing.
How can this be done? Thanks.
You have to use
WC()
which is an alias ofglobal $woocommerce
to access WooCommerce related data, and to access cart information you have to useWC()->cart
.
This code should work for you.
add_filter('woocommerce_order_button_text', 'woo_custom_order_button_text');
function woo_custom_order_button_text()
{
$cart_total = WC()->cart->total;
return __('Your text ' . $cart_total, 'woocommerce');
}
Hope this helps!