How to correctly add your message to the “Thank you” page? Woocommerce 3

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to correctly add your message to the “Thank you” page? Woocommerce 3



Example
Need add custom message after "Thank you. Your order has been received.". A variable has been added to my message. It contains the percentage of the total amount of the order. In general, I think that this is a working option, but if there are errors, please write the correct answer.


add_filter('woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 10, 2 );
function woo_change_order_received_text( $str, $order ) {
// Get order total
$order_total = $order->get_total();
$percent = get_option( 'wc-custom-percent' ); // Percentage
$order_saving = (float)($percent * $order_total / 100); // Bonus amount

$new_str = $str . ' You participate in the bonus program, your bonus interest from this order is' . $order_saving . ' euros. <a href="#">Learn more about the bonus program.</a>';
return $new_str;
}




2 Answers
2


add_action( 'woocommerce_thankyou', 'my_custom_thankyou_page', 20 );
function my_custom_thankyou_page( $order_id ){
$order = wc_get_order($order_id);
$order_total = $order->get_total();
$percent = get_option( 'wc-custom-percent' ); // Percentage
$order_saving = (float)($percent * $order_total / 100); // Bonus amount

$new_str = ' You participate in the bonus program, your bonus interest from this order is' . $order_saving . ' euros. <a href="#">Learn more about the bonus program.</a>';
return $new_str;

}



Your code is correct, but you could make it a bit better using sprintf() and translatable texts:


sprintf()


add_filter('woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 20, 2 );
function woo_change_order_received_text( $thankyou_text, $order ) {
$order_saving = (float)( get_option( 'wc-custom-percent' ) * $order->get_total() / 100 ); // Bonus amount
$bonus_link = '#';

return sprintf( __("%s You participate in the bonus program, your bonus interest from this order is %s. %s", "woocommerce"),
$thankyou_text,
wc_price($order_saving),
'<a href="'.$bonus_link.'">' . __("Learn more about the bonus program.", "woocommerce") . '</a>' );
}



Code goes in function.php file of the active child theme (or active theme). tested and works.



enter image description here






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

H1Y6gfG5C
O UkKX9rnpcd T6TU5qxAC YDnzuki0Gq jh,RsCAvd6eMCNrBr1x Z26YiHw1cOZk9qq,dm1qUa,MQ In8df0JXjcTa8qG,cYB0f4 T 8Cd1j

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results