Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
}
@Martahv

This comment has been minimized.

Copy link

@Martahv Martahv commented Jan 18, 2018

I'm getting a warning message which is visible in all pages in my staging site:
Warning: Missing argument 2 for woo_personalize_order_received_title() in .../functions.php on line 74

how can I sort this out ?

@ashokrane

This comment has been minimized.

Copy link

@ashokrane ashokrane commented Apr 26, 2018

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