replacement of Category widget in WordPress e-Commerce

It took me several hours to understand that default e-Commerce category list widget is not working correctly, due to incorrect working of some core functions.

Jelouse Design posted a great article on replacing WPSC category list widget with the means of default WordPress functions – WP E-commerce Category list order and more control…

I needed to customize a little the code to suit my needs.
See the following:

//here we get terms of current wpsc category. NOTE: my WPSC is placed on the page with slug 'product-page'. Replace it with yours.
$terms = get_term_by('slug',
                            preg_replace('/\/products-page\//','',$_SERVER['REQUEST_URI']),
                            'wpsc_product_category');
// id of current wpsc category
 $myCat = $terms->term_id;

	    $args = $args = array(
 'orderby'            => 'name',
 'order'              => 'ASC',
 'show_last_update'   => 0,
 'style'              => 'list',
 'show_count'         => 0,
 'hide_empty'         => 0,
 'use_desc_for_title' => 1,
 'child_of'           => 0,
 'hierarchical'       => true,
 'title_li'           => __( 'Categories' ),
 'show_option_none'   => __('No categories'),
 'number'             => NULL,
 'echo'               => 1,
 'depth'              => 2,
 'current_category'   => $myCat,
 'pad_counts'         => 0,
 'taxonomy'           => 'wpsc_product_category',
 'walker'             => 'Walker_Category' );
 wp_list_categories( $args );

This code gave me tree of categories, where current category has class ‘current-cat’

1 comment

Leave a Reply

%d bloggers like this: