• Resolved dinahemmingsen

    (@dinahemmingsen)


    For administrative purposes, I need to know the category when I get a new order. I have tried to insert the code below in functions.php child theme, but it unfortunately reports errors.

    Code that does not work in functions.php child theme:

    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);

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show category on ‘new order’ mail’ is closed to new replies.