Get Category Slug on Single Product Page

In wpsc_single-product.php:

//get cat of product
$query_data = Array();
$pr_post_id = wpsc_the_product_id();
$categories = wp_get_object_terms($pr_post_id , 'wpsc_product_category' );
//if product is associated with more than one category
if(count($categories) > 1 && isset($wpsc_query->query_vars['wpsc_product_category']))
$query_data['category'] = $wpsc_query->query_vars['wpsc_product_category'];
elseif(count($categories) > 0)
$query_data['category'] = $categories[0]->slug;

Then you can use the category slug as follows for example:

if($query_data['category'] == "t-shirts"){ //show size charts; ?>
//show size charts

This is based on a useful function posted here:

http://isabelcastillo.com/highlight-current-category-in-menu-on-single-product-page-wpec

Leave a Comment