Removing time ago in WordPress Admin for WooCommerce Subscriptions

Tags
Author

Had a request to remove the time ago in the WordPress admin for a number of fields. I was able to override this for parent orders on WooCommerce subscriptions.

<?php 

if( ! function_exists( 'prefix_highlight_post_date_with_readable_format' ) ) :
	function prefix_highlight_post_date_with_readable_format( $t_time = '', $post = object, $date = '', $mode = '' ) {

		// If current list post type is not a `post`?
		// Then return default date format.
	if( 'shop_order' == $post->post_type || 'shop_subscription' == $post->post_type) {
		    $t_time = get_the_time( _x( 'Y/m/d g:i:s A', 'post date', 'woocommerce-subscriptions' ), $post );
			return $t_time;
	} else {
		    return $t_time;
	}
		
}
   	add_filter( 'post_date_column_time', 'prefix_highlight_post_date_with_readable_format', 10, 4 );
endif;

But changing the time ago columns for post types in the WordPress backend isn’t possible since it’s a core function of WordPress.

I found the following articles helpful.

The solution was the following code

<?php

// define the human_time_diff callback 
function filter_human_time_diff( $since, $diff, $from, $to ) { 
    // make filter magic happen here... 
    $friendly_date = date_i18n( 'Y-m-d H:i:s', $to );
    $friendly_date_remove = str_replace('ago','',$friendly_date);
    return $friendly_date_remove;
}; 
         
// add the filter 
add_filter( 'human_time_diff', 'filter_human_time_diff', 10, 4 );

add_filter( 'gettext', 'ago_translate_text', 10, 3 );
function ago_translate_text( $translated_text, $untranslated_text, $domain ) {
    if ( 'woocommerce-subscriptions' !== $domain ) {
        return $translated_text;
    }
 
    $translated_text = str_replace( ' ago', '', $translated_text );
    return $translated_text;
}

I don’t like it, but it works.