Support

Account

Home Forums General Issues Display custom field value with woocommerce order

Unread

Display custom field value with woocommerce order

  • Hi

    I’ve managed to add a custom field called “manager” to the Order view. It works correctly (meaning = it displays). Now i would like to create a loop to display values of this field in the following way:

    ‘manager field’ value | number of orders

    but i have no clue how to do that. This is what i’ve managed to create so far:

    <table class="table table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <th class="row-title">manager</th>
                                        <th>no of orders</th>
                                    </tr>
                                    </thead>
    
                                    <tbody>
                                <?php
                                global $woocommerce, $post;
                                $filters = array(
                                    'post_status' => 'completed',
                                    'post_type' => 'shop_order',
                                    'posts_per_page' => -1,
                                    'orderby' => 'modified',
                                    'order' => 'DESC'
                                );
    
                                $loop = new WP_Query($filters);
    
                                while ($loop->have_posts()) {
                                    $loop->the_post();
                                    $order = new WC_Order($loop->post->ID);
                                    $items = $order->get_items();
                                    $acf_value = get_field( 'manager', $order );
    								 ?>
    
                                        <tr class="">
                                            <td class="row-title"><?php echo $acf_value; ?></td>
                                            <td></td>
                                      
                                        </tr>
    
                                        <?php
    
                                 }
                                 ?>
                             </tbody>
    
                         </table>

    but it displays nothing. how to display the value of the field correctly?

Viewing 1 post (of 1 total)

The topic ‘Display custom field value with woocommerce order’ is closed to new replies.