• Resolved aharm

    (@aharm)


    Hi,

    I’ve just started to use pods as I’m finding it far better than ACF Pro for relationships.

    I’ve created a bi-direcitonal relationship between the ‘event’ post type (created by an events plugin) to WooCommerce ‘Order’ post type.

    Everything is working perfectly except I cannot get the WooCommerce Order object to display correctly in the admin events view.

    Currently it displays the order in the following format: ‘Order – August 2, 2021 @ 10:57 AM’

    This makes it really hard to identify the correct order to select, so I want to change this to show by order ID which in this example would be ‘#10244 (billing name)’

    Could you please let me know how this can be done within pods?

    Please see image links below for example:

    https://ruzi-my.sharepoint.com/:i:/g/personal/alex_harmer_ruzi_com_au/EVLacjkRBhlMiXvmX3XsGp8B6mXM6VJcA3LcMCxPTi9s3Q?e=pvRawB

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Paul Clark

    (@pdclark)

    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;
    		}
    
    	}
    );
    Plugin Author Jory Hogeveen

    (@keraweb)

    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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Displaying relationship to WooCommerce Order by Order ID’ is closed to new replies.