While trying to do this with the_title
filter, I found the filter in Pods wasn’t getting the order ID. Here’s a code block that adds the Order ID and billing name to the title by looking up the order ID by timestamp:
<?php
add_filter(
'the_title',
function( $title ) {
/**
* the_title would normally take a second argument, $id,
* but for some reason there is a fatal error being thrown from Pods
* when trying to hook in with the second $id argument.
*
* So instead, the below block filters by title text only
* and looks up the shop_order by timestamp.
*/
if ( false === strpos( $title, 'Order ' . htmlentities( '–' ) ) ) {
return $title;
}
$time = trim( str_replace( [ 'Order', '@', '–', htmlentities('–') ], [ '', '', '', '' ], $title ) );
$timestamp = strtotime( $time );
$orders = get_posts([
'post_type' => 'shop_order',
'post_status' => 'any',
'date_query' => [
'year' => date( 'Y', $timestamp ),
'month' => date( 'n', $timestamp ),
'day' => date( 'j', $timestamp ),
'hour' => date( 'H', $timestamp ),
'minute' => date( 'i', $timestamp ),
],
]);
$id = $orders[0]->ID;
$name = get_post_meta( $id, '_billing_first_name', true ) . ' ' . get_post_meta( $id, '_billing_last_name', true );
if ( ! empty( $orders ) ) {
return str_replace(
'Order ',
'Order #' . $id . ' – ' . $name . ' ',
$title
);
}else {
return $title;
}
}
);
Closing topic due to no reply! Feel free to reopen if needed.
Cheers, Jory
Thread Starter
aharm
(@aharm)
Hi Paul and Jory,
Thanks for your thoughtful response and the code block.
I added your code block by a snippet but unfortunately it still wouldn’t show the order by name on my system.
Funnily enough though, I still had the same ACF relatiosnhip field turned on, and the snippet actually fixed how the ACF field was rendering the order name, but didn’t do it for pods.
I’ve since deactivated ACF but pods still just uses timestamp.
Is there another variant of the snippet you could provide for me to try?
Thanks!