Display list of Published Products by default in WooCommerce admin panel

I have a website where I sell my products and in the back-end, I want to show the Published products by default. Right now All products are shown by default.

This code changes displays (screenshot attached) Published posts by default. I want the same thing happening for WooCommerce Products.

Will you be able to help.

  • Dimitris Kalliris
    • Support Team Lead

    Hello there Steve McGough,

    hope you’re doing good today! :slight_smile:

    I went ahead and created a new MU plugin file in your server:

    wp-content/mu-plugins/woo-products-admin.php

    and in there I added the following snippet:

    <?php
    // change WooCommerce Products link to display published products only
    function woo_change_admin_products_link() {
    global $submenu;
    $submenu['edit.php?post_type=product'][5][2] = 'edit.php?post_status=publish&post_type=product';
    }
    add_action( 'admin_menu', 'woo_change_admin_products_link' );

    Now the Products admin menu URL is changed with the “published” parameter.

    Warm regards,

    Dimitris

  • Steve McGough
    • Site Builder, Child of Zeus

    Thank you. Question. Would it be appropriate to place this code directly in the functions.php file? That’s usually what I do with code snippets like this. Keeps everything in one place that can be reviewed in the future.

    Just wondering what the best practice would be?

    Steve

  • Steve McGough
    • Site Builder, Child of Zeus

    Update – I found this…

    https://bjornjohansen.no/mu-plugins

    I pretty much exclusively use Child themes for all of my sites. If it’s a child theme, I assume it would be OK to keep these code snippets in the functions.php file for the child theme.

    Let me know if that is not the case, or if there is an advantage to using mu-plugins?

    Is using either the functions.php or the mu-plugins route any faster concerning site performance?

    Thank you!

    Steve

  • Dimitris Kalliris
    • Support Team Lead

    Hello Steve :slight_smile:

    I prefer having only theme-specific stuff in functions.php file of child-theme, as this makes more sense to me. This can also make things like a theme change easier, as well as using the same snippet in other installations that use another theme.

    It’s also a personal matter though, so if you think that this way it’s going to be easier for you to manage, then it doesn’t make any difference.

    Warm regards,

    Dimitris