0

add_filter( 'woocommerce_my_account_my_orders_columns', 'ecommercehints_weight_column_my_account_orders_table', 10, 1 );
function ecommercehints_weight_column_my_account_orders_table( $columns ) {
    $weight_column = [];
    foreach ( $columns as $key => $name ) {
        $weight_column[ $key ] = $name;
        if ( 'order-status' === $key ) { // Insert new column after Total column\
            $weight_column['order-category'] = __( 'Event', 'woocommerce' );
         }
    }
    return $weight_column;
}
 add_action( 'woocommerce_my_account_my_orders_column_order-category', 'ecommercehints_get_order_category', 3, 1 );
function ecommercehints_get_order_category( $order ) {
    $items = $order->get_items(); 
    foreach ( $items as $item ) {      
        $product_id = $item->get_product_id();
        $terms = get_the_terms ( $product_id, 'product_cat' );
        //var_dump($terms);
        foreach ( $terms as $term ) {
             echo $term->name.'</br>'; 
             break;
        }
    }
    //var_dump($items);
}

Jagdish Sarma Asked question April 7, 2023
Add a Comment