xxxxxxxxxx
// Get all product categories
$terms = get_terms(array('taxonomy' => 'product_cat', 'hide_empty' => 0));
// Loop through all product categories
foreach ($terms as $key => $value) {
// Get category name
$term_name = $value->name;
// Get category link
$term_link = get_term_link($value, 'product_cat');
// Output link and name
echo '<li><a href="' . $term_link . '">' . $term_name . '</a></li>';
}
xxxxxxxxxx
$terms = get_the_terms( $product_id, 'product_cat' );
foreach ($terms as $term) {
$product_cat_id[] = $term->term_id;
}
xxxxxxxxxx
$categories_html = get_the_term_list($product->ID, 'product_cat', '', ', ');
$categories_text = strip_tags($categories_html);
echo $categories_text;
xxxxxxxxxx
/**
*
* Add Product Tags Above The Add To Cart Form
*
*/
add_action( 'woocommerce_before_add_to_cart_form', 'dwc_print_tags_under_description' );
function dwc_print_tags_under_description() {
// This will hold all of our product tags
$tags = array();
// get an array of the WP_Term objects for a defined product ID (get_the_id() will return the product id of the current object)
$terms = wp_get_post_terms( get_the_id(), 'product_tag' );
// Loop through each product tag for the current product
if ( count( $terms ) > 0 ) {
foreach( $terms as $term ) {
// Product Tag Name
$term_name = $term->name;
// Product Tag Link
$term_link = get_term_link( $term, 'product_tag' );
// Set the product tag names in an array
$tags[] = '<a class="product-tag-badge" href="'.$term_link.'">' . $term_name . '</a>';
}
// Combine all of the product tags into one string for output
$tags = implode( '', $tags );
// Output
echo $tags;
}
}