Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vishalck
Last active May 28, 2019 18:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vishalck/83ca61f864850b739b8bc4aa6dc8e642 to your computer and use it in GitHub Desktop.
Save vishalck/83ca61f864850b739b8bc4aa6dc8e642 to your computer and use it in GitHub Desktop.
Personalize the WooCommerce Thank You page
<?php
add_filter( 'the_title', 'woo_personalize_order_received_title', 10, 2 );
function woo_personalize_order_received_title( $title, $id ) {
if ( is_order_received_page() && get_the_ID() === $id ) {
global $wp;
// Get the order. Line 9 to 17 are present in order_received() in includes/shortcodes/class-wc-shortcode-checkout.php file
$order_id = apply_filters( 'woocommerce_thankyou_order_id', absint( $wp->query_vars['order-received'] ) );
$order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['key'] ) ? '' : wc_clean( $_GET['key'] ) );
if ( $order_id > 0 ) {
$order = wc_get_order( $order_id );
if ( $order->get_order_key() != $order_key ) {
$order = false;
}
}
if ( isset ( $order ) ) {
//$title = sprintf( "You are awesome, %s!", esc_html( $order->billing_first_name ) ); // use this for WooCommerce versions older then v2.7
$title = sprintf( "You are awesome, %s!", esc_html( $order->get_billing_first_name() ) );
}
}
return $title;
}
@ashokrane
Copy link

You need to pass 2 arguments to the function. One is the title & second is the order id parameter, labelled as $id. It seems you are not passing the 2nd argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment