Skip to content

Instantly share code, notes, and snippets.

@bradleysa
Created April 22, 2022 07:54
Show Gist options
  • Save bradleysa/29f550cd6103f966f8bd92851cd2c0b8 to your computer and use it in GitHub Desktop.
Save bradleysa/29f550cd6103f966f8bd92851cd2c0b8 to your computer and use it in GitHub Desktop.
WC: Personalizing the thank you page title
function rp4wp_title_order_received( $title, $id ) {
if ( is_order_received_page() && get_the_ID() === $id ) {
global $wp;
$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->order_key != $order_key ) {
unset( $order );
}
}
if ( isset ( $order ) ) {
$title = sprintf( "Thank you, %s!", esc_html( $order->billing_first_name ) );
}
}
return $title;
}
add_filter( 'the_title', 'rp4wp_title_order_received', 10, 2 );
/** https://rudrastyh.com/woocommerce/thank-you-page.html **/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment