John Davidson

php - Change Order received title issue in WooCommerce

0 comments
Message:


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?



My Answer:
&& is_order_received_page() ) {
$title = 'Thank you for your order!';
}
return $title;
}

However, the issue is that this code changes the title of all pages to 'Thank you for your order!' when it should only change the title of the 'order received' page in WooCommerce.

To fix this issue, you can modify the code to check if the current page is the 'order received' page by checking the post ID. Here's an updated version of the code:

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

function woo_title_order_received( $title, $id ) {
if ( is_order_received_page( $id ) ) {
$title = 'Thank you for your order!';
}
return $title;
}


By passing the post ID to the `is_order_received_page()` function, you can ensure that the title is only changed on the 'order received' page in WooCommerce.

Rate this post

5 of 5 based on 7306 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us