Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

If I go to

wp-content/themes/theme-name/woocommerce/single-product/meta.php

then I see this code:-

<?php
/**
 * Single Product Meta
 *
 * @author      WooThemes
 * @package     WooCommerce/Templates
 * @version     1.6.4
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

global $post, $product;
?>
<div class="product_meta">

    <?php echo $product->get_categories( ', ', ' <span class="posted_in">'.__('Category:', GETTEXT_DOMAIN).' ', '.</span>'); ?>

    <?php echo $product->get_tags( ', ', ' <span class="tagged_as">'.__('Tags:', GETTEXT_DOMAIN).' ', '.</span>'); ?>

</div>

What modifications are required so that it doesn't display the category, having slug, certain-category-slug ?

I could have used the following:-

get_categories( array( 'exclude' => 'certain-category-slug' ) )

but I believe that WooCommerce $product->get_categories is different from WordPress API get_categories because their arguments are different.

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

You are right about woocommerce: get_categories() being different from wordpress: get_categories(), the woocommerce function uses get_the_term_list(), so there is no way to exclude categories, same applies to get_the_category_list(). You can use wp_list_categories() for this, especially take a look at this example from the codex page:

Display Categories Assigned to a Post

Display the categories (or terms from other taxonomies) assigned to a post ordered by parent-child category relationship. Similar to the function get_the_category_list() which orders the categories by name. This example must be used inside the loop.

Code:

$taxonomy = 'category';

// get the term IDs assigned to post.
$post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
// separator between links
$separator = ', ';

if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) {

    $term_ids = implode( ',' , $post_terms );
    $terms = wp_list_categories( 'title_li=&style=none&echo=0&taxonomy=' . $taxonomy . '&include=' . $term_ids );
    $terms = rtrim( trim( str_replace( '<br />',  $separator, $terms ) ), $separator );

    // display post categories
    echo  $terms;
}

This isn't a complete solution, you have to construct a function based on this and use your new function instead of the default inside meta.php.

share|improve this answer
    
Your answer helped a lot in finding directions. However, I thought that instead of writing so much code just do a quick dirty hack: <?php echo str_replace("Category Name","",$product->get_categories( ', ', ' <span class="posted_in">'.__('Category:', GETTEXT_DOMAIN).' ', '.</span>')); ?> –  Omar Tariq Nov 17 '13 at 3:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.