mercredi 22 juin 2016

WooCommerce: Displaying the sorting sub-category on sub-categories too

I have found a WooCommerce code snippet that adds sorting on Category pages, and it works.

But the problem is that the sorting subcategory is only displayed on the Parent category page, but not in the subcategories pages.

can some one tell me what should I add to my code, to change that?

Here is this code:

function tutsplus_product_subcategories( $args = array()) {
$parentid = get_queried_object_id(); 
$args = array(
    'parent' => $parentid
);

$terms = get_terms( 'product_cat', $args );

if ( $terms) {

    echo '<ul class="wooc_sclist">';

        foreach ( $terms as $term ) {

            echo '<li class="category">';                 


                echo '<h2>';
                    echo '<a href="' .  esc_url( get_term_link( $term ) ) . '" class="' . $term->slug . '">';
                        echo $term->name;
                    echo '</a>';
                echo '</h2>';

            echo '</li>';


        }

        echo '</ul>';
    }
}
add_action( 'woocommerce_before_shop_loop', 'tutsplus_product_subcategories', 50 );



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire