A
A
alexiusgrey2021-11-23 19:28:20
WordPress
alexiusgrey, 2021-11-23 19:28:20

I see the list of my orders only if I log in as an admin, how can I make it visible to every user?

I display the list of orders in a separate custom account tab so that users can see it.
The default table is very far from the desired design, and I display them with my markup.
When I log in as an admin, I see all my orders. I try to register and place an order from a random user - the tab remains empty.
Where can there be an error and how to correctly catch the id of the current user? I do via get_current_user_id().

The whole code of the withdrawal cycle orders.

<section class="order">
<?php 
$orders = wc_get_orders( array(
  'numberposts' => -1,
   'orderby' => 'date',
   'order' => 'DESC',
  'author' => get_current_user_id(),
) );


//* Loop through each WC_Order object
foreach( $orders as $order ){?>
    <div class="order-wrapper product d-flex col-12">
        <?php 
        $order_data = $order->get_data(); // The Order data
        $order_id = $order_data['id'];
        $order_currency = $order_data['currency'];
        $order_status = $order_data['status']; ?>
        <div class="order-number">#<?php echo  $order_id;?></div>         
        <div class="order-inner">
            <div class="order-inner-top">
                <?php    
                foreach ($order->get_items() as $key => $lineItem) {
                $product_id = $lineItem['product_id'];
                $product = wc_get_product( $product_id );
               
                $item_meta_data = $lineItem->get_meta_data();
                $colormeta = $lineItem->get_meta( 'pa_color', true );
                $sizemeta = $lineItem->get_meta( 'pa_size', true ); 
                echo '<div class="order-inner-top-inner"><div class="order-slider-inner"> <div class="order-inner-left"><div class="order-image">' . $product->get_image(['322', '304']) . '</div></div>';  
                echo '<div class="order-inner-right"><div class="order-info-item order-info-item-name">' . $lineItem['name'] . '</div><div class="order-info-item order-info-item "><span class="order-price">' .  $lineItem['total'] . ' '  . $order_currency  .   '</span></div><div class="order-item-quantity"> '. ' Quantity: ' . $lineItem['qty'] . '</div>';
                echo '<div class="order-item-metas">' . $colormeta . ' , ' . $sizemeta . '</div>';
                echo '</div></div></div>';}  ?>
          </div>          
          
          <div class="order-inner-bottom">
               <div class="d-flex justify-content-center">
                    <button class="order-total"><?php echo get_theme_mod('orders_total_button');?></button> 
              </div>
              <div class="totals-toggle">
                  <div class="order-info-item bottom"> <span>Total Price:</span><span class="order-total-price"> <?php echo $order->get_total() . '  ' . $order_currency; ?></span></div>       
                  <div class="order-info-item bottom"> <span>Total Quantity:</span> <?php echo  $order->get_item_count(); ?> item(s)</div>         
                  <div class="order-info-item bottom"> <span>Status:</span> <?php echo $order_status;?></div>
                  <div class="order-info-item bottom"> <span>Order Date: </span> <?php echo $order->order_date; ?></div>
                </div>
          </div> 
        </div>       
 </div> 
<?php  }?>
</section>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question