Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Retrieve the cat and subcat link in a div for woocommerce WordPress

  • REFUND REQUESTED

As you see currently woocommerce retrieve the category and subcategory as meta on single product page. I need to retrieve this link separately and possibly in div so I can format them with css easily.

Answers (2)

2013-09-03

Arnav Joy answers:

can you please describe your question more.


Jihan Ahmed comments:

okay.. if u go this link http://turbo-marketing-internet.com/vinewine/shop/australian-wines/australian-red/all-saints-sangiovese-cabernet/ and notice Main Category: Australia and sub-category: Red wines this are need to link to it proper category.

Notice the links on the breadcrumbs. Woocommerce has also on template to show all categories main cat, sub cat but altogether these are found at meta.php

Thanks for your time !

2013-09-03

Liam Bailey answers:

Here is what Woocommerce does for its category breadcrumbs:


if ( is_category() ) {

$cat_obj = $wp_query->get_queried_object();
$this_category = get_category( $cat_obj->term_id );

if ( $this_category->parent != 0 ) {
$parent_category = get_category( $this_category->parent );
echo get_category_parents($parent_category, TRUE, $delimiter );
}

echo $before . single_cat_title( '', false ) . $after;

}


So you could do something like:

if ( is_category() ) {

$cat_obj = $wp_query->get_queried_object();
$this_category = get_category( $cat_obj->term_id );

if ( $this_category->parent != 0 ) {
echo "<div class='parent-cat-link'>" . get_category_link($this_category->parent) . "</div>";

}
echo "<div class='subcat-link'>" . get_category_link($cat_obj->term_id) . "</div>";
}