phpwordpresswoocommerceendpointpage-title

Change Order received title issue in WooCommerce


I have the following code which works and changes the title of the 'order received' page:

add_filter( 'the_title', 'woo_title_order_received', 10, 2 );

function woo_title_order_received( $title, $id ) {
    if ( function_exists( 'is_order_received_page' ) && 
         is_order_received_page() && get_the_ID() === $id ) {
        $title = "Thank you, good luck!";
    }
    return $title;
}

However it causes a fatal error on the shop page due to Too few arguments to function woo_title_order_received(). After checking online I found that the_title isn't correct and it should be get_the_title. If I change it to that the fatal error goes away, but it no longer changes the title on the order received page.

None of the other snippets I've found online have worked, and I can't see why the above stops the shop pages from working. Any ideas?


Solution

  • Try to set $id argument to null (useful when it's not defined):

    add_filter( 'the_title', 'woo_title_order_received', 10, 2 );
    function woo_title_order_received( $title, $id = null ) {
        if ( function_exists( 'is_order_received_page' ) &&
             is_order_received_page() && get_the_ID() === $id ) {
            $title = "Thank you, good luck!";
        }
        return $title;
    }
    

    It could work…