Created
May 25, 2022 13:44
-
-
Save runezero/24b2ca7b11915de48e6afbf42e6a1a56 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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