WooCommerce垂直下拉产品父类别的菜单

时间:2018-02-03 14:32:38

标签: wordpress drop-down-menu woocommerce

我在woocommerce中有大约100个父类别,唯一的解决方案是类别的下拉菜单。我有下面的脚本,但它也显示子类别,这是更加压倒性的。

任何人都知道如何编辑此脚本以不显示子类别?

/**
 * WooCommerce Extra Feature Shortcode
 * --------------------------
 *
 * Register a shortcode that creates a product categories dropdown list
 *
 * Use: [product_categories_dropdown orderby="title" count="0" hierarchical="0"]
 *
 */
add_shortcode( 'product_categories_dropdown', 'woo_product_categories_dropdown' );
function woo_product_categories_dropdown( $atts ) {
    extract(shortcode_atts(array(
        'show_count'    => '0',
        'hierarchical'  => '0',
        'orderby'       => ''
    ), $atts));

    ob_start();

    $c = $count;
    $h = $hierarchical;
    $o = ( isset( $orderby ) && $orderby != '' ) ? $orderby : 'order';

    // Stuck with this until a fix for http://core.trac.wordpress.org/ticket/13258
    wc_product_dropdown_categories( $c, $h, 0, $o );
    ?>
    <script type='text/javascript'>
    /* <![CDATA[ */
        var product_cat_dropdown = jQuery(".dropdown_product_cat");
        product_cat_dropdown.change(function() {
            if ( product_cat_dropdown.val() !=='' ) {
                location.href = "<?php echo home_url(); ?>/?product_cat="+product_cat_dropdown.val();
            }
        });
    /* ]]> */
    </script>
    <?php

    return ob_get_clean();
}

0 个答案:

没有答案