Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce - Print Processing orders. A template page snippet to (if you are logged in as admin) output all of your orders with 'processing' status (paid) ready for printing.
<?php
/*
Template Name: Print Processing Orders :)
*/
if (!is_user_logged_in() || !current_user_can('manage_options')) wp_die('This page is private.');
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php _e('Processing Orders'); ?></title>
<style>
body { background:white; color:black; width: 95%; margin: 0 auto; }
table { border: 1px solid #000; width: 100%; }
table td, table th { border: 1px solid #000; padding: 6px; }
article { border-top: 2px dashed #000; padding: 20px 0; }
</style>
</head>
<body>
<header>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1 class="title"><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</header>
<section>
<?php
global $woocommerce;
$args = array(
'post_type' => 'shop_order',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'shop_order_status',
'field' => 'slug',
'terms' => array('processing')
)
)
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$order_id = $loop->post->ID;
$order = new WC_Order($order_id);
?>
<article>
<header>
<h2>Order #<?php echo $order_id; ?> &mdash; <time datetime="<?php the_time('c'); ?>"><?php echo the_time('d/m/Y'); ?></time></h2>
</header>
<table cellspacing="0" cellpadding="2">
<thead>
<tr>
<th scope="col" style="text-align:left;"><?php _e('Product', 'woothemes'); ?></th>
<th scope="col" style="text-align:left;"><?php _e('Quantity', 'woothemes'); ?></th>
<th scope="col" style="text-align:left;"><?php _e('Price', 'woothemes'); ?></th>
</tr>
</thead>
<tfoot>
<tr>
<th scope="row" colspan="2" style="text-align:left; padding-top: 12px;"><?php _e('Subtotal:', 'woothemes'); ?></th>
<td style="text-align:left; padding-top: 12px;"><?php echo $order->get_subtotal_to_display(); ?></td>
</tr>
<?php if ($order->order_shipping > 0) : ?><tr>
<th scope="row" colspan="2" style="text-align:left;"><?php _e('Shipping:', 'woothemes'); ?></th>
<td style="text-align:left;"><?php echo $order->get_shipping_to_display(); ?></td>
</tr><?php endif; ?>
<?php if ($order->order_discount > 0) : ?><tr>
<th scope="row" colspan="2" style="text-align:left;"><?php _e('Discount:', 'woothemes'); ?></th>
<td style="text-align:left;"><?php echo woocommerce_price($order->order_discount); ?></td>
</tr><?php endif; ?>
<?php if ($order->get_total_tax() > 0) : ?><tr>
<th scope="row" colspan="2" style="text-align:left;"><?php _e('Tax:', 'woothemes'); ?></th>
<td style="text-align:left;"><?php echo woocommerce_price($order->get_total_tax()); ?></td>
</tr><?php endif; ?>
<tr>
<th scope="row" colspan="2" style="text-align:left;"><?php _e('Total:', 'woothemes'); ?></th>
<td style="text-align:left;"><?php echo woocommerce_price($order->order_total); ?> <?php _e('- via', 'woothemes'); ?> <?php echo ucwords($order->payment_method); ?></td>
</tr>
</tfoot>
<tbody>
<?php echo $order->email_order_items_table(); ?>
</tbody>
</table>
<h2><?php _e('Customer details', 'woothemes'); ?></h2>
<?php if ($order->billing_email) : ?>
<p><strong><?php _e('Email:', 'woothemes'); ?></strong> <?php echo $order->billing_email; ?></p>
<?php endif; ?>
<?php if ($order->billing_phone) : ?>
<p><strong><?php _e('Tel:', 'woothemes'); ?></strong> <?php echo $order->billing_phone; ?></p>
<?php endif; ?>
<div style="float:left; width: 49%;">
<h3><?php _e('Billing address', 'woothemes'); ?></h3>
<p>
<?php echo $order->get_formatted_billing_address(); ?>
</p>
</div>
<div style="float:right; width: 49%;">
<h3><?php _e('Shipping address', 'woothemes'); ?></h3>
<p>
<?php echo $order->get_formatted_shipping_address(); ?>
</p>
</div>
<div style="clear:both;"></div>
</article>
<?php endwhile; ?>
</section>
</body>
</html>
@vegaix9

This comment has been minimized.

Copy link

@vegaix9 vegaix9 commented Dec 10, 2011

Played around with this. It would be very handy used to print individual processing orders from the orders list and within the editor.

@daisypeel

This comment has been minimized.

Copy link

@daisypeel daisypeel commented Feb 14, 2012

The shipping address is not returned as of the latest Woocommerce update. Shipping address customer name is there, just no address.

@Ramoonus

This comment has been minimized.

Copy link

@Ramoonus Ramoonus commented Feb 15, 2012

whats new?

@daisypeel

This comment has been minimized.

Copy link

@daisypeel daisypeel commented Feb 16, 2012

Thanks! Suggestion - I changed a line to change the payment method displayed. Lots of users don't want to think they paid via Paypal even though I'm using Paypal Pro to process CCards. So I put payment_method == "paypal_pro") { echo "Credit Card"; } else { echo ucwords($order->payment_method); } ?> in - so it says paid with CC :)

@joseamirandavelez

This comment has been minimized.

Copy link

@joseamirandavelez joseamirandavelez commented Sep 27, 2012

Really nice code! I hacked it a little bit to allow me to mark orders as complete. I also created a new one that shows completed orders. Im trying to add the same link to mar orders as processing in that one but it doesnt work...

@TechDaddyK

This comment has been minimized.

Copy link

@TechDaddyK TechDaddyK commented May 23, 2013

Thanks for providing this! My problem is that I don't need it displayed on the screen; I need to export all orders to a CSV file on demand. Does anyone know how to accomplish this?

@sr4k

This comment has been minimized.

Copy link

@sr4k sr4k commented May 23, 2013

I'm with TechDaddyK. Looking for a daily order report in CSV format for both inventory tracking (we sell off line too) and for fulfillment center.

@Sasni

This comment has been minimized.

Copy link

@Sasni Sasni commented May 28, 2013

Could you help me to show the customer note?

@monkeyperson

This comment has been minimized.

Copy link

@monkeyperson monkeyperson commented Aug 20, 2013

hi. thanks for this code! any way to add the product skus into it? would be helpful to enter orders with lots of variable skus in easier. thanks.

@mikeve

This comment has been minimized.

Copy link

@mikeve mikeve commented Oct 1, 2013

Hi

This looks like exactly what I want, but I can't get it to work. I get the title but then a blank page.

I downloaded the php file and put in my themes directory and the created a page using the new template - nada.

What am I doing wrong?

Thanks

Mike

@mikeve

This comment has been minimized.

Copy link

@mikeve mikeve commented Oct 2, 2013

Never mind!

I found out that I didn't have any orders with the status of processing. Doh!

Mike

@emirir

This comment has been minimized.

Copy link

@emirir emirir commented Feb 25, 2014

hi

how i can print "order comments" with this form?

@lonchbox

This comment has been minimized.

Copy link

@lonchbox lonchbox commented Mar 31, 2014

Thanx a lot for this code :)

If you put this code in the functions.php to add a link to that page in the adminbar, I think is very useful too.

function mytheme_admin_bar_render() {
    global $wp_admin_bar;
    // we can add a submenu item too
    $wp_admin_bar->add_menu( array(
        'id' => 'print_orders',
        'title' => __('Print Orders'),
        'href' => get_bloginfo('url').'/processing-orders/',
        'meta'  => array(
            //'title' => __('Print Orders'),
            'target' => '_blank',
            'class' => 'woo_print_orders'
        ),
    ) );
}
// and we hook our function via, just for admin use role
if( current_user_can('administrator') ) {
    add_action( 'wp_before_admin_bar_render', mytheme_admin_bar_render' );
}

The href locate the page URL, I use that slug for the page but if you use a different one just change the URL.

@pipoulito

This comment has been minimized.

Copy link

@pipoulito pipoulito commented Oct 10, 2014

hi , this is great !
but how can i do to have this only for a specific customer ID ?
thanks

@nortwin

This comment has been minimized.

Copy link

@nortwin nortwin commented Nov 11, 2014

Hi...thanks a lot for this, it works great. Would it be possible to output the list as products instead of as orders??? any help would be much appreciated...

thanks

@spiderflystudios

This comment has been minimized.

Copy link

@spiderflystudios spiderflystudios commented Dec 17, 2014

Is there a way to mod this to show only those of other statuses? For instance, I tried to change the array from "processing" to "complete"...and it showed all the ones processing too. Seems like this code, as is, only works correctly with the processing status.

Someone should turn this into a full plugin that will work with any of the stock or custom statuses. Would be an immense help.

@agentben96

This comment has been minimized.

Copy link

@agentben96 agentben96 commented Jan 22, 2015

How can I make this display custom meta info for products on it? I know the meta fields names, but I don't know how to make them display for that order. Also it needs to divide the total for a product if there is more than 1 QTY. For example, it says QTY 2 = $114

It will need to also show (per piece price) which would be $57
And the Item (SKU) Number needs to be displayed.

A lot I know, But I will be very grateful if someone could help me with this.

@r9tee

This comment has been minimized.

Copy link

@r9tee r9tee commented Mar 12, 2015

This is very cool Mike. Thanks for creating this.

I am hopeful that you or someone else could tell me how to make the page show all orders for a specific product and also, make it easy for someone to query different products via id or name on the page and have it generate the report.

Thanks again!

@nikicampbell

This comment has been minimized.

Copy link

@nikicampbell nikicampbell commented May 22, 2015

It there a way of making it print from just a specific category? Or actually instead I would want to exclude two specific product categories :)

thanks in advance!
Niki

@scottmcculloch

This comment has been minimized.

Copy link

@scottmcculloch scottmcculloch commented Aug 19, 2015

Hey @nikicampbell,

Did you ever figure out how to print from just a specific category (or to exclude categories)? That's exactly what I'm looking for and haven't been able to get it to work. I found this:
http://wpquestions.com/question/showChrono/id/8301

But it doesn't work. :(

Thanks,
Scott

@duncang17

This comment has been minimized.

Copy link

@duncang17 duncang17 commented Aug 20, 2015

Hello handy code, thanks,

Is there a simple way of printing a list of just the marked orders (i.e. ones which have been manually checked in the checkbox on the admin orders page)?
All I really require is a simple printed list of the checked orders, with order numbers and order total, plus total of the totals .

Any plugins to achieve this?

Cheers Duncan

@Vernsloth

This comment has been minimized.

Copy link

@Vernsloth Vernsloth commented Oct 8, 2015

@nikicampbell & @scottmcculloch

This is not fast or a great way to iterate through the categories but this will print after a slower loading time:

'shop_order', 'post_status' => 'publish', 'orderby' => 'post_date', 'order' => 'DESC', 'posts_per_page' => -1, 'tax_query' => array( array( 'taxonomy' => 'shop_order_status', 'field' => 'slug', 'terms' => array( 'processing'), ), ``` ), ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); //echo '
' . print_r($post, true) . '
'; $order_id = $loop->post->ID; $order = new WC_Order($order_id); $items = $order->get_items(); foreach ($items as $key => $value) { $id = $value['product_id']; $terms = get_the_terms( $id, 'product_cat' ); //echo '
' . print_r($terms, true) . '
'; foreach ($terms as $term) { if( $term->slug == 'YOUR-PRODUCT-CATEGORY-SLUG' ){ $product-category = true; break 2; } else { //echo 'NO' . '
'; } } } if ($product-category ) : ?>
           <article>
    <header>
        <h2>Order #<?php echo $order_id; ?> &mdash; <time datetime="<?php the_time('c'); ?>"><?php echo the_time('M - d/Y'); ?></time></h2>
    </header>
    <table cellspacing="0" cellpadding="2">
        <thead>
            <tr>
                <th scope="col" style="text-align:left;"><?php _e('Product', 'woothemes'); ?></th>
                <th scope="col" style="text-align:left;"><?php _e('Quantity', 'woothemes'); ?></th>
                <th scope="col" style="text-align:left;"><?php _e('Price', 'woothemes'); ?></th>
            </tr>
        </thead>
        <tfoot> 
            <tr>
                <th scope="row" colspan="2" style="text-align:left; padding-top: 12px;"><?php _e('Subtotal:', 'woothemes'); ?></th>
                <td style="text-align:left; padding-top: 12px;"><?php echo $order->get_subtotal_to_display(); ?></td>
            </tr>
            <?php if ($order->order_shipping > 0) : ?><tr>
                <th scope="row" colspan="2" style="text-align:left;"><?php _e('Shipping:', 'woothemes'); ?></th>
                <td style="text-align:left;"><?php echo $order->get_shipping_to_display(); ?></td>
            </tr><?php endif; ?>
            <?php if ($order->order_discount > 0) : ?><tr>
                <th scope="row" colspan="2" style="text-align:left;"><?php _e('Discount:', 'woothemes'); ?></th>
                <td style="text-align:left;"><?php echo woocommerce_price($order->order_discount); ?></td>
            </tr><?php endif; ?>
            <?php if ($order->get_total_tax() > 0) : ?><tr>
                <th scope="row" colspan="2" style="text-align:left;"><?php _e('Tax:', 'woothemes'); ?></th>
                <td style="text-align:left;"><?php echo woocommerce_price($order->get_total_tax()); ?></td>
            </tr><?php endif; ?>
            <tr>
                <th scope="row" colspan="2" style="text-align:left;"><?php _e('Total:', 'woothemes'); ?></th>
                <td style="text-align:left;"><?php echo woocommerce_price($order->order_total); ?> <?php _e('- via', 'woothemes'); ?> <?php echo ucwords($order->payment_method); ?></td>
            </tr>
        </tfoot>
        <tbody>
            <?php echo $order->email_order_items_table(); ?>
        </tbody>
    </table>
         </article>

  <?php else : ?>

<?php endwhile; ?>
@xyzcardiff

This comment has been minimized.

Copy link

@xyzcardiff xyzcardiff commented Apr 15, 2017

After updating to woocommerce 3.03, this is now broken :(

It needs to be updated according to the new CRUD classes.

I have no idea how to do this :( Can anyone assist?

Thanks

@jnasevich

This comment has been minimized.

Copy link

@jnasevich jnasevich commented Apr 29, 2017

The original code set $args for WP_Query() call using the following code:
$args = array( 'post_type' => 'shop_order', 'post_status' => 'publish', 'posts_per_page' => -1, 'tax_query' => array( array( 'taxonomy' => 'shop_order_status', 'field' => 'slug', 'terms' => array('processing') ) ) );

However, after upgrading WooCommerce to version 3.0.4, if you look in database in wp_posts table, you will notice that WooCommerce has added a "wc-" prefix to the values of the post_status field. So the values in the post_status field are now, for example:

  • wc-cancelled
  • wc-completed
  • wc-refunded
  • wc-processing

In addition, the taxonomy query (tax_query) no longer appears to be necessary, at least for my purposes. WooCommerce documentation still lists shop_order_status as a valid taxonomy, but my query no longer works when I include it.

So my revised $args statement looks like the following:
$args = array( 'post_type' => 'shop_order', 'post_status' => 'wc-processing', 'posts_per_page' => -1 );

Hope this helps!

@dschiffner

This comment has been minimized.

Copy link

@dschiffner dschiffner commented May 25, 2017

@jnasevich - thanks for catching that! I was pulling my hair out for two days. Can't believe I looked over something so simple :P

@rughooker

This comment has been minimized.

Copy link

@rughooker rughooker commented Jul 3, 2017

I still cannot get this to work. Can someone post the entire revised code. I must be missing something simple. I'm not a coder, so what may be obvious to a coder, is slipping right past me.

@Antoinebr

This comment has been minimized.

Copy link

@Antoinebr Antoinebr commented Jul 15, 2017

Woocommerce changed

This works

global $woocommerce;
	
	$args = array(
		'post_type'			=> 'shop_order',
		'post_status' 		=> 'wc-processing',
    'posts_per_page' => -1,
	);
	
	$loop = new WP_Query( $args );
	
  if($loop->have_posts()) :
	while ( $loop->have_posts() ) : $loop->the_post();
	
		$order_id = $loop->post->ID;
		
		$order = new WC_Order($order_id);
		
    echo $order->get_formatted_billing_address();
      
    echo $order->get_formatted_shipping_address();

  endwhile;
	
  else :

    echo "Nothing found";

  endif;
@anji-sandage

This comment has been minimized.

Copy link

@anji-sandage anji-sandage commented Oct 25, 2017

Does anyone have a working copy of this page template? I am trying to get it to work with the current version of woocommerce. Thanks!

@peterpenguw

This comment has been minimized.

Copy link

@peterpenguw peterpenguw commented Mar 16, 2020

this is a core shopify feature that comes easily to shopify users. At version 4.0.0 it's still not integrated with WooCommerce? Sad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.