Reputation:
The idea here is to include the price (example: $40) with the button text, making it like this: "Place Order & Pay $40".
That is the expected outcome but the code I'm using (with or without wc_price()
) only generates a span tag on the button.
I know that I can just add the currency symbol myself into the button text, but the idea is to make it global.
My code so far:
add_filter('woocommerce_order_button_text', 'place_order_button_with_order_total');
function place_order_button_with_order_total(){
$order_value = wc_price(WC()->cart->total);
return __('Place Order & Pay '.$order_value., 'woocommerce');
}
How do I change the code to include the price in the button text?
Upvotes: 4
Views: 447
Reputation: 3116
You can remove the HTML markup that you get when using wc_price
(or in my example get_total()
) with the strip_tags()
function.
Also you shouldn't add variables to translatable strings. If you want to make a combination of a translatable string and a variable value you can make use of the sprintf()
function.
The following code should do the trick:
add_filter('woocommerce_order_button_text', 'place_order_button_with_order_total');
function place_order_button_with_order_total(){
return sprintf( '%s %s', __( 'Place Order & Pay', 'custom-order-button' ), strip_tags( WC()->cart->get_total() ) );
}
Upvotes: 2