Hi is it possible to add and use ajax to get new orders without refresh or reload the page??
How to achieve this? Thanks
Current standard loop code I have is below:
<?php
$args = array(
'post_type' =>'shop_order',
'post_status' => 'publish',
'posts_per_page' => 50,
'order' => 'DESC',
'item_meta' => array (
'_sku' => 'ABCD',
)
);
?>
<table id="tblExport" class="demotable1" style="border:1px solid black; ">
<thead>
<tr>
<th ><?php _e('ID:', ' '); ?></th>
<th ><?php _e('Product:', ' '); ?></th>
<th ><?php _e('Date:', ' '); ?></th>
<th ><?php _e('Value:', ' '); ?></th>
<th ><?php _e('Name:', ' '); ?></th>
<th ><?php _e('E-mail:', ' '); ?></th>
<th ><?php _e('status:', ' '); ?></th>
</tr>
</thead>
<tbody id="export-pla" >
<?php
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$order_id = $loop->post->ID;
$order = new WC_Order($order_id);
?>
<tr>
<td>
<?php
//ID - order
if ($order->id) : ?><?php echo $order->id; ?><?php endif;?>
</td>
<td>
<?php
// product name
if (sizeof($order->get_items())>0) { foreach($order->get_items() as $item)
{ $_product = get_product( $item['product_id'] ); echo '' . $item['name'] . ''; } }
?>
</td>
<td>
<?php echo the_time('d/m/Y'); ?>
</td>
<td>
<?php if ($order->order_total): $preco_format=($order->order_total);?>
<?php echo $trata_preco=number_format($preco_format, 2, ",", "."); ?><?php endif; ?>
</td>
<td>
<?php if ($order->billing_first_name) : ?><?php echo $order->billing_first_name; ?><?php endif; ?>
<?php if ($order->billing_last_name) : ?><?php echo $order->billing_last_name; ?><?php endif; ?>
</td>
<td>
<?php if ($order->billing_email) : ?><?php echo $order->billing_email; ?><?php endif; ?>
</td>
<td>
<?php if ($order->status) : ?><?php echo $order->status; ?><?php endif; ?>
</td>
</tr>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</tbody>
</table>
Kyle answers:
Are you trying to get more orders (the next 50) or reload this exact template (refresh action) without reloading? If it is the first do you want it done as the user scrolls, if it is the second do you want a button?
email889 comments:
Sorry for the delay. Somehow, I stop receiving email notifications. I didn't know there was comment added.
I would like to show all ('posts_per_page' => -1), and auto get orders / load new orders without reload the page.
email889 comments:
Actually dont worry about the auto get orders. will be set to ('posts_per_page' => -1).
And the ajax is Just load additional orders, if there is any (NEW) order received without refreshing/reloading the whole page again.