Published By and Last updated By
-
Hi
We want to show the last modified and last update products by users in backend of woocomerce
We found this code, but it shows the name of user randomly wrong!
Why?
// Add custom columns to product list
function last_updatedcustom_columns($columns) {
$columns['published_by'] = 'Published By';
$columns['last_updated_by'] = 'Last updated By';
return $columns;
}
add_filter('manage_product_posts_columns', 'last_updatedcustom_columns');
// Populate custom columns with data
function last_updatedcustom_column_data($column, $post_id) {
switch ($column) {
case 'published_by':
$published_by = get_post_field('post_author', $post_id);
$published_by_user = get_userdata($published_by);
if ($published_by_user) {
$published_by_name = $published_by_user->display_name;
$published_date = get_the_date('Y-m-d H:i:s', $post_id);
echo $published_by_name . ' <br> (' . $published_date . ')';
}
break;
case 'last_updated_by':
$last_updated_by = get_post_meta($post_id, '_edit_last', true);
$last_updated_by_user = get_userdata($last_updated_by);
if ($last_updated_by_user) {
$last_updated_by_name = $last_updated_by_user->display_name;
$last_updated_date = get_the_modified_date('Y-m-d H:i:s', $post_id);
echo $last_updated_by_name . ' <br> (' . $last_updated_date . ')';
}
break;
}
}
add_action('manage_product_posts_custom_column', 'last_updatedcustom_column_data', 10, 2);
/*Charge Product Columns Content*/
function woo_product_extra_columns_content($column)
{
global $post;
$product_id = $post->ID;
switch ($column)
{
case "product_ID":
echo $product_id;
break;
}
}
add_action("manage_posts_custom_column", "woo_product_extra_columns_content");
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.