简体   繁体   中英

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)

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.)

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM