Categories

Saturday, December 21, 2024
#919814419350 therichposts@gmail.com
WoocommerceWoocommerce HooksWordpress HooksWordpress Tricks

How to make custom Woocommerce my order page template WordPress?

Hello to all, welcome again on therichpost.com. In this post, I will tell you, How to make custom Woocommerce my order page template WordPress?

Post Working:

This post code is useful for, if you want to show seperate user orders items. Each login user can see his/her order woocommerce items. And you can make separate template file and use this code. I am also getting woocommerce ordered item image.

Here is the complete code and you can add this into your theme’s template file

<?php /* Template Name: My Account - Review Orders */ ?>
<?php get_header() ?>
  <div class="content-container">
    <div class="container">
      <div class="row">
        <div class="col-md-12 main-wrap" itemprop="mainContentOfPage" role="main">
          <div class="main-content">
                        
                        <div class="my_account_page_review_orders">
            <?php
            ## ==> Define HERE the statuses of that orders 
$order_statuses = array('wc-on-hold', 'wc-processing', 'wc-completed');

## ==> Define HERE the customer ID
$customer_user_id = get_current_user_id(); // current user ID here for example

// Getting current customer orders
$customer_orders = wc_get_orders( array(
    'meta_key' => '_customer_user',
    'meta_value' => $customer_user_id,
    'post_status' => $order_statuses,
    'numberposts' => -1
) );


// Loop through each customer WC_Order objects
foreach($customer_orders as $order ){

    // Order ID (added WooCommerce 3+ compatibility)
    $order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;

    // Iterating through current orders items
    foreach(wc_get_order($order_id)->get_items() as $item_id => $item_values)
  { 
  ?>
  
   <div class="col-sm-4">
      <div class="panel panel-primary">
        <div class="panel-heading text-center"><?php echo $item_values['name']; ?></div>
        <div class="panel-body"><?php 
    
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $item_values['product_id'] ));?>

       <img src="<?php  echo $image[0]; ?>" class="img-responsive"></div>
        <div class="panel-footer text-center"><?php echo wc_get_order_item_meta( $item_id, 'pa_materiali', true ); ?></div>
     <div class="panel-footer text-center"><?php echo wc_get_order_item_meta( $item_id, 'pa_colori', true ); ?></div>
      </div>
    </div>

  <?php }
} 
?>
        
                      

          </div>
        </div>
      </div>
    </div>
  </div>
        
</div>
<?php get_footer() ?>



 

If you have any kind of query then please do comment below.

Jassa

Thank you

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.