Hi,
I suggest creating an extra column for this on the product page.
Step 1, the header
/**
* Add edited date column on product page (header)
*/
function add_edited_date_product_column_header( $columns ) {
//add column header
$columns['edited_date'] = __( 'Edited date', 'woocommerce' );
return $columns;
}
add_filter( 'manage_edit-product_columns', 'add_edited_date_product_column_header', 10, 1 );
Step 2, the content
/**
* Add edited date column on product page (content)
*/
function add_edited_date_product_column_content( $column, $postid ) {
// add column content
if ( $column == 'edited_date' ) {
// Get product object
$product = wc_get_product( $postid );
// Get product date modified
$date_modified = $product->get_date_modified();
// Echo output
echo 'Modified' . '<br><span title="' . $formatted_date = date( 'Y/m/d h:i:s a', strtotime( $date_modified ) ) . '">' . $formatted_date = date( 'd F Y', strtotime( $date_modified ) ) . '</span>';
}
}
add_action( 'manage_product_posts_custom_column', 'add_edited_date_product_column_content', 10, 2 );
Step 3, make the column sortable
/**
* Make the edited date column on the product page sortable
*/
function edited_date_product_column_sortable( $columns ) {
$columns['edited_date'] = 'edited_date';
//To make a column 'un-sortable' remove it from the array
//unset($columns['date']);
return $columns;
}
add_filter( 'manage_edit-product_sortable_columns', 'edited_date_product_column_sortable', 10, 1 );
Step 4, orderby. This not yet finished! you may try to find the query yourself as a challenge, good luck!
/**
* Orderby edited_date (product)
*/
function edited_date_product_column_orderby( $query ) {
if( ! is_admin() )
return;
$orderby = $query->get('orderby');
// edited date, product
if( $orderby == 'edited_date' ) {
//$query->set( 'orderby', '' );
}
}
add_action( 'pre_get_posts', 'edited_date_product_column_orderby' );
Regards