Can't show the product name on table using get_name();

217 views Asked by At

I can't echo the product name on my order page. I'm using ultimate member plugin with WooCommerce. "get_id();" is working just fine. I used "$order->get_name()" to echo the ordered product name. but it shows me error when tried to load the page.

 <tbody>
        <?php
            foreach( $customer_orders as $customer_order ) {
                $order = wc_get_order( $customer_order->ID );
                $order_id = $customer_order->ID;
                $order_data = $order->get_data();
                $order_date = strtotime( $order->get_date_created() );
                ?>

        <tr class="order" data-order_id="<?php echo esc_attr( $order_id ); ?>">
            <?php do_action( 'um_woocommerce_orders_tab_before_table_row', $order, $customer_orders ); ?>


            <td class="order-total" data-title="<?php _e( 'Item', 'um-woocommerce' ); ?>">
                <?php echo $order->get_name() ?></td>





            <td class="order-date" data-title="<?php _e( 'Date', 'um-woocommerce' ); ?>">
                <time
                    datetime="<?php echo wp_date( 'Y-m-d', $order_date ); ?>"><?php echo wp_date( $date_time_format, $order_date ); ?></time>
            </td>
            <td class="order-status" data-title="<?php _e( 'Status', 'um-woocommerce' ); ?>">
                <span
                    class="um-woo-status <?php echo $order->get_status(); ?>"><?php echo wc_get_order_status_name( $order->get_status() ); ?></span>
            </td>
            <td class="order-total" data-title="<?php _e( 'Total', 'um-woocommerce' ); ?>">
                <?php echo $order->get_formatted_order_total() ?></td>
            <td class="order-detail">
                <a href="<?php echo esc_url( "$url#$order_id" ); ?>" class="um-woo-view-order um-tip-n"
                    title="<?php esc_attr_e( 'View order', 'um-woocommerce' ); ?>"><i class="um-icon-eye"></i></a>
                <?php do_action( 'um_woocommerce_orders_tab_actions', $order, $customer_orders ); ?>
            </td>
            <?php
                    if ( UM()->options()->get('woo_account_order_ations') ) {
                        $actions = wc_get_account_orders_actions( $order );
                        echo '<td class="order-actions">';
                        if ( !empty( $actions ) ) {
                            foreach ( $actions as $key => $action ) {
                                echo '<a href="' . esc_url( $action['url'] ) . '" class="button ' . sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) . '</a>';
                            }
                        }
                        echo '</td>';
                    }
                    ?>
            <?php do_action( 'um_woocommerce_orders_tab_after_table_row', $order, $customer_orders ); ?>
        </tr>

        <?php } ?>
    </tbody>
1

There are 1 answers

0
mujuonly On

There is no get_name() function for order object. You need loop through the order items to get the product object and use the $product->get_name() function

    <?php foreach ($order->get_items() as $item_key => $item) { 
        $product = $item->get_product();
    
    ?>
    <td class="order-total" data-title="<?php _e( 'Item', 'um-woocommerce' ); ?>">
        <?php echo $product->get_name() ?>
    </td>
    <?php } ?>