skip to Main Content

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?

2

Answers


  1. No idea why you should use the_title WordPress hook with multiple if conditions, while WooCommerce has specific hooks for that.

    The 'woocommerce_endpoint_' . $endpoint . '_title' filter hook allows to change the Order received title.

    So you get:

    /**
     * @param string $title Default title.
     * @param string $endpoint Endpoint key.
     * @param string $action Optional action or variation within the endpoint.
     */
    function filter_woocommerce_endpoint_order_received_title( $title, $endpoint, $action ) {   
        $title = __( 'Thank you, good luck!', 'woocommerce' );
     
        return $title;
    }
    add_filter( 'woocommerce_endpoint_order-received_title', 'filter_woocommerce_endpoint_order_received_title', 10, 3 );
    
    Login or Signup to reply.
  2. 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…

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search