So I have this weird request about displaying what sub-categories a product is assigned to in the order emails being sent out upon order confirmation in WooCommerce - however I would only like to show the categories from a specific category parent.
You see, I have two main-categories in WooCommerce, one being Brands and the other being Categories. I'd like to only display the sub-categories being assigned to a specific product under the Brands category. In my case the Brands category (parent) has the ID 15.
The code snippet that I have currently tested and is confirmed working is this
function modfuel_woocommerce_before_order_add_cat($name, $item){
$product_id = $item['product_id'];
$_product = wc_get_product( $product_id );
$htmlStr = "";
$cats = "";
$terms = get_the_terms( $product_id, 'product_cat' );
$count = 0;
foreach ( $terms as $term) {
$count++;
if($count > 1){
$cats .= $term->name;
}
else{
$cats .= $term->name . ',';
}
}
$cats = rtrim($cats,',');
$htmlStr .= $_product->get_title();
$htmlStr .= "<p>Category: " . $cats . "</p>";
return $htmlStr;
}
add_filter('woocommerce_order_item_name','modfuel_woocommerce_before_order_add_cat', 10, 2);
Any way someone here knows what I could add in the code above in order to get what I need?
Thanks!