Last active
October 8, 2024 22:20
-
-
Save vishalck/83ca61f864850b739b8bc4aa6dc8e642 to your computer and use it in GitHub Desktop.
Personalize the WooCommerce Thank You page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
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
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 ?