• Resolved raha1988ab

    (@raha1988ab)


    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)
  • Plugin Support ckadenge (woo-hc)

    (@ckadenge)

    Hi @raha1988ab,

    Thank you for reaching out.

    Helping out with custom coding of this nature is outside the scope of support, although I would recommend the following:

    1. Running the exact question you’re asking, along with the code provided, through an AI platform like ChatGPT for recommendations/changes to your code;
    2. Checking whether there are existing plugins in the WordPress plugin repository that might be doing that already. A quick search pointed out some good candidates.
    3. Joining our WooCommerce Slack community (it does have a developer channel where you can ask coding questions): https://woo.com/community-slack/

    Hope it helps!

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.