Skip to content

Instantly share code, notes, and snippets.

@nixonmedia
Last active February 15, 2018 16:16
Show Gist options
  • Save nixonmedia/82c1fe401dda559b154d1ec29d64d010 to your computer and use it in GitHub Desktop.
Save nixonmedia/82c1fe401dda559b154d1ec29d64d010 to your computer and use it in GitHub Desktop.
<?php
/*
Template Name: Orders
*/
get_header();
?>
<div class="container">
<h1 class="title"><?php the_title(); ?></h1>
<?php
if (!is_user_logged_in()){
echo 'You must be logged in to view this page. ';
}else{
?>
<div class="tools">
<a class="print pull-right" href="javascript:window.print();">Print Page</a>
</div>
<ul>
<?php
$params = array(
'post_type' => 'product',
'posts_per_page' => -1,
'post_status' => 'any',
)
; // (1)
$wc_query = new WP_Query($params);
global $product;
global $post;
?>
<?php if ($wc_query->have_posts()) : ?>
<?php
while ($wc_query->have_posts()) :$wc_query->the_post();
$productID = $product->id;
?>
<li><h2><?php the_title(); ?></h2>
<ul class="list-unstyled">
<?php
$filters = array(
'post_status' => 'any',
'post_type' => 'shop_order',
'posts_per_page' => -1,
'orderby' => 'modified',
'order' => 'ASC'
);
$loop = new WP_Query($filters);
echo '<ul class="list-unstyled orders">';
if ($loop->have_posts()){?>
<li> <!--<h3>Orders:</h3>-->
<?
while ($loop->have_posts()) {
$loop->the_post();
$order = new WC_Order($loop->post->ID);
$order_id = $loop->post->ID;
$total_seats = 0;
foreach ($order->get_items() as $key => $o) {
$customer = new WC_Customer( $order_id );
//echo 'lID = ' . $lineItem['product_id'];
if($productID == $o['product_id']){
?>
<li>
<article>
<!--
<pre>
<?php print_r($order); ?>
</pre>
-->
<!--<p><?php echo $order->get_formatted_billing_address(); ?></p>
<strong>Number of seats: </strong> <?php echo $o['qty']; ?><br>
<strong>Purchase Date </strong><?php echo the_time('m/d/Y'); ?><br>-->
<!--<?php if ($order->billing_email) : ?>
<strong><?php _e('Email:', 'woothemes'); ?></strong> <?php echo $order->billing_email; ?><br>
<?php endif; ?>-->
<?php
?>
<?php if ($order->billing_first_name) : ?>
<?php $first = $order->billing_first_name; ?>
<?php echo $first; ?>
<?php endif; ?>
<?php if ($order->billing_last_name) : ?>
<?php $last = $order->billing_last_name; ?>
<?php echo $last; ?>
<?php endif; ?>
<?php if ($order->billing_phone) : ?>
<?php $phone = $order->billing_phone;?>
- <?php echo $phone; ?>
<?php endif; ?>
<?php if ($order->billing_phone) : ?>
<?php $phone = $order->billing_phone;?>
| Seats: <?php echo $o['qty']; ?><br>
<?php endif; ?>
</article>
</li>
<?php }
}
}
}else{
echo 'No orders yet';
}
echo '</ul>';
?>
</ul>
</li>
<?php endwhile; ?>
<?php else: ?>
<p>
<?php _e( 'No Products' ); ?>
</p>
<?php endif; ?>
</ul>
</div>
<!--
<div role="tabpanel" class="tab-pane" id="all">
<<div class="tools">
<a class="print pull-right" href="javascript:window.print();">Print Page</a>
</div>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
<?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')
)
)
);
$loop1 = new WP_Query( $args );
$count = 1;
while ( $loop1->have_posts() ) : $loop1->the_post();
$order_id = $loop1->post->ID;
$order = new WC_Order($order_id);
?>
<article class="c-<?php echo $count; ?>">
<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>
<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) : ?>
<?php
$phone = $order->billing_phone;
?>
<p><strong><?php _e('Tel:', 'woothemes'); ?></strong> <?php echo formatPhoneNumber($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; $count++; ?>
</section>
</div><!--/.container
<?php } ?>
</div><!--/.container-->
<?php get_footer(); ?>
<script>
$ = jQuery;
$('td.td').each(function(){
$(this).removeAttr('style');
$(this).css('border', '1px solid #000');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment