woocommerce widget product categories

WordPress with woocommerce installed has the option to show a dropdown of woocommerce product categories. I only wanted to show the children of a particular category. So I put the code shown below in functions.php. (found this helpful tip by googling) This works.

But some functionality is lost. Because without the filter after I choose a category the newly loaded page shows the chosen category active/selected in the drop down menu. But with the filter in my functions.php the category isn’t remembered. Is there a argument or another way to get this functionality back. (this I couldn’t find on the web)

Read More
add_filter( 'woocommerce_product_categories_widget_dropdown_args', 'wpsites_product_cat_widget' );

function wpsites_product_cat_widget( $args ) {

$args = array(
    'hierarchical' => 0,
    'hide_empty' => 0,
    'parent' => 11,
    'taxonomy' => 'product_cat',
    );

return $args;
}

I hope someone has a golden tip.

(Also I find it hard to find good documentation on woocommerce. WordPress has good documentation. Any tips on this are also welcome. Maybe I missed some resources out there.)

Related posts

1 comment

  1. try this..

    add_filter( 'woocommerce_product_categories_widget_dropdown_args', 'wpsites_product_cat_widget' );
    
    function wpsites_product_cat_widget( $args ) {
    global $wp_query;
    
    $args = array(
        'hierarchical' => 0,
        'hide_empty' => 0,
        'parent' => 11,
        'taxonomy' => 'product_cat',
        'selected' => isset( $wp_query->query_vars['product_cat'] ) ? $wp_query->query_vars['product_cat'] : '',
        );
    
    return $args;
    }
    

Comments are closed.