Show all Categories in Order Email
-
Hi,
I need my woocommerce order emails to show all categories listed, currently it is only showing the last subcategory. I have parent-category-subcategories-subcategories. I added this code to the functions.php file:
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);
But it only shows the last subcategory and I need it show all categories. Could you please help with editing the code to add them or advise what I should do?
The page I need help with: [log in to see the link]
- The topic ‘Show all Categories in Order Email’ is closed to new replies.