dongwei1895 2016-01-29 11:32
浏览 85
已采纳

woocommerce小部件产品类别

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

  • 写回答

1条回答 默认 最新

  • duanbai1370 2016-01-29 12:14
    关注

    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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失