WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
back to parent category (2 posts)

  1. numero7
    Member
    Posted 1 year ago #

    Hi im looking to add a "back to product category" button in my single product page with no success ( the link should send me back to the parent product category). I've tried the get category function with no luck...
    someone can help ?
    thanks a million...

    http://wordpress.org/extend/plugins/woocommerce/

  2. bheadrick
    Member
    Posted 1 year ago #

    um, isn't that what breadcrumbs are for?

    get_category just prints out link(s) to the applicable categories. You need to use get_terms to access the taxonomy objects and find the ones with no parent

    $terms = get_the_terms($post->ID,'product_cat');
    
    $count = count($terms); $i=0;
    if ($count > 0) {
        $term_list = '<span class="parent_category">Parent Category:';
        foreach ($terms as $term) {
            $i++;
    if($term->parent==0){
        	$term_list .= '<a href="/product-category/' . $term->slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . '</a>';
        	if ($count != $i) $term_list .= ' &middot; '; }
        }
        echo $term_list .'</span>';

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic