WooCommerce products filter by tags within admin

Need the ability to filter the WooCommerce products list within admin by tags? Snippet of code below is for you. This concept can be edited for other purposes.

This can be easily changed to work in different scenarios.

Found this snippet on the following website.

https://businessbloomer.com/woocommerce-display-custom-filters-wp-dashboard-products/

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2 Comments

  1. Dan Rickman

    Hey Shane! Not sure if you’re monitoring this, but I’m struggling with an implementation of this. Quick question, if I were to use the code for a product attribute (in my example, artist), how would I get the “selected” to work? How would I target the attribute/term? What I have now:

    add_filter( ‘woocommerce_product_filters’, ‘drick_filter_by_custom_taxonomy_dashboard_products’ );

    function drick_filter_by_custom_taxonomy_dashboard_products( $output ) {

    global $wp_query;

    $output .= wc_product_dropdown_categories( array(
    ‘show_option_none’ => ‘Filter by artist’,
    ‘taxonomy’ => ‘pa_artist’,
    ‘name’ => ‘pa_artist’,
    ‘hide_empty’ => 0,
    ‘selected’ => isset( $wp_query->query_vars[‘pa_artist’] ) ? $wp_query->query_vars[‘pa_artist’] : ”, //THIS IS NOT WORKING
    ) );

    return $output;
    }

    Maybe $wp_query->query_vars is not the right way? Appreciate any help you can provide.

    • I would probably just try using somthing along the lines of

      'selected' => $_GET['pa_artist'] ?? '',