WooCommerce: Output a printable list of processing orders

Someone requested a way to print out a list of their processing orders for WooCommerce so I came up with a snippet to do so 🙂

The code below can be added as a page template in your theme. Once added to your template, just create a page in WordPress admin and assign it the “Print processing orders” page template.

Theres a check at the top of the page to only let admin users in, and when viewed the page will give you a nice list of processing orders which you can then print out.

<?php
/*
Template Name: Print Processing Orders
*/
if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
	wp_die( 'This page is private.' );
}
?>
<style>
	body { background: white; color: black; width: 95%; margin: 0 auto; }
	table { border: 1px solid #000; width: 100%; border-collapse: collapse; }
	table td, table th { border: 1px solid #000; padding: 6px; text-align: left; }
	article { border-top: 2px dashed #000; padding: 20px 0; }
</style>

<?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>
		<h2>Order #<?php echo $order_id; ?> &mdash; <a href="<?php echo admin_url( 'post.php?post=' . $order_id . '&action=edit' ); ?>">view order</a></h2>

		<table>
			<tr><th>Subtotal</th><td><?php echo $order->get_subtotal_to_display(); ?></td></tr>
			<?php if ( $order->order_shipping > 0 ) : ?>
				<tr><th>Shipping</th><td><?php echo $order->get_shipping_to_display(); ?></td></tr>
			<?php endif; ?>
			<?php if ( $order->order_discount > 0 ) : ?>
				<tr><th>Discount</th><td><?php echo woocommerce_price( $order->order_discount ); ?></td></tr>
			<?php endif; ?>
			<?php if ( $order->get_total_tax() > 0 ) : ?>
				<tr><th>Tax</th><td><?php echo woocommerce_price( $order->get_total_tax() ); ?></td></tr>
			<?php endif; ?>
			<tr><th>Total</th><td><?php echo woocommerce_price( $order->order_total ); ?> (<?php echo $order->payment_method; ?>)</td></tr>
		</table>

		<?php echo $order->email_order_items_table(); ?>

		<?php if ( $order->billing_email ) : ?>
			<p>Email: <?php echo $order->billing_email; ?></p>
		<?php endif; ?>
		<?php if ( $order->billing_phone ) : ?>
			<p>Phone: <?php echo $order->billing_phone; ?></p>
		<?php endif; ?>

		<h3>Billing address</h3>
		<p><?php echo $order->get_formatted_billing_address(); ?></p>

		<h3>Shipping address</h3>
		<p><?php echo $order->get_formatted_shipping_address(); ?></p>
	</article>

	<?php
endwhile;
wp_reset_postdata();
?>
← Say hello to WooCommerce; simple,... Debugging with WP_DEBUG_LOG →