Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanlukasz/437a0cd78f88359145a6a9a0d15cb147 to your computer and use it in GitHub Desktop.
Save kanlukasz/437a0cd78f88359145a6a9a0d15cb147 to your computer and use it in GitHub Desktop.
[Admin products sort by date] Adds the modified date to the Admin product column and gives the option to sort products by date modified #woocommerce
add_filter( 'manage_edit-product_columns', 'admin_products_sort_modified', 9999 );
function admin_products_sort_modified( $columns ){
$columns['laatst_bijgewerkt'] = 'Laatst bijgewerkt';
return $columns;
}
add_action( 'manage_product_posts_custom_column', 'admin_products_sort_modified_content', 10, 2 );
function admin_products_sort_modified_content( $column, $product_id ){
if ( $column == 'laatst_bijgewerkt' ) {
//echo strtotime(get_the_modified_date("Y-m-d H:i:s", $product_id));
echo get_the_modified_date("d F Y \o\m H:i", $product_id);
}
}
add_filter( 'manage_edit-product_sortable_columns', 'admin_products_sort_modified_sortable' );
function admin_products_sort_modified_sortable( $columns ){
$columns['laatst_bijgewerkt'] = 'laatst_bijgewerkt';
return $columns;
}
add_action( 'pre_get_posts', 'reorder_sortable_column' );
function reorder_sortable_column( $query ) {
if( ! is_admin() )
return;
$orderby = $query->get( 'orderby');
if( 'laatst_bijgewerkt' == $orderby ) {
$query->set('orderby','modified');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment