Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

shop_order auto load WordPress

  • SOLVED

Hi I'd like to add functionality (like ajax) to load Real Time NEW order on the page without refresh/reloading page. So, any new order will be loaded automatically.


Current standard loop code I have is below:
<?php
$args = array(
'post_type' =>'shop_order',
'post_status' => 'publish',
'posts_per_page' => -1,
'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>

Answers (4)

2016-11-14

Reigel Gallarde answers:

the easiest way is to add this on your functions.php file... that's just it....

add_action( 'wp_footer','woocommerce_auto_load_shop_order', 9999 );

function woocommerce_auto_load_shop_order() {
global $wp;
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
$refresh_time = 2000;
?>
<script>
jQuery(function($){
setInterval(function(){
if ($( "#tblExport" ).length > 0)
$( "#tblExport" ).load( "<?php echo $current_url; ?> #tblExport" );
}, <?php echo $refresh_time; ?> )
});
</script>
<?php
}


you can change the value of $refresh_time... 2000 just means every 2 seconds... change to 5000 if you wanted it every 5 seconds...


Reigel Gallarde comments:

this is assuming that you have a table with an id tblExport on your page...


Reigel Gallarde comments:

have you tried this? let me know if there's a problem.


email889 comments:

Thank you. I Tried it, however, it is slowing down the site.


Reigel Gallarde comments:

if your code is what you mentioned as your "Current standard loop", then that should not slow... however, there might be other factors... if I can see the page, I can give you solutions...

as for my code, maybe this can help if we change the <script> part like this..


<script>
jQuery(function($){
if ($( "#tblExport" ).length > 0) {
setInterval(function(){
$( "#tblExport" ).load( "<?php echo $current_url; ?> #tblExport" );
}, <?php echo $refresh_time; ?> );
}
});
</script>


email889 comments:

If I set shorter time to refresh. User cant complete checkout.. .
Checkout page just loading continuously.


email889 comments:

can you please add some code for transition or indication to show when the new order item / is added. like a highlight background color or flash with fade out.


Reigel Gallarde comments:

wait... I'm just confused...

hmm... are we on the checkout page? what really are you trying to do?

My code above assumes you are at a custom page, viewing table with data on it... so with this I have come up with the solution to refresh the table part... but I'm not sure why there's a checkout in there as you mention... my code should not run on the checkout page...


email889 comments:

Your code is used on the custom page. It is correct.

However, when used interval below 10000, this affects the whole site to load very slow and checkout cannot complete. I haven't tried your updated code though.

Checkout page was mentioned due to I had to do a fake order to see how your code add new order to the shop order loop in action.


Reigel Gallarde comments:

can you please try the to the update the <script> part with the new code given above... I think that would fixed the issue... if that is fixed we can then move on with transitions...


Reigel Gallarde comments:

this should be the new code that should go to functions.php


add_action( 'wp_footer','woocommerce_auto_load_shop_order', 9999 );

function woocommerce_auto_load_shop_order() {
global $wp;
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
$refresh_time = 2000;
?>
<script>
jQuery(function($){
if ($( "#tblExport" ).length > 0) {
setInterval(function(){
$( "#tblExport" ).load( "<?php echo $current_url; ?> #tblExport" );
}, <?php echo $refresh_time; ?> );
}
});
</script>
<?php
}


email889 comments:

Yup, second one works better.


email889 comments:

are you doing the transition?


email889 comments:

Quick question:

Currently your code is updating the page based on $refresh_time. Instead, Can you tweak your current code to update based on when the new order is made?

For example, there is "woocommerce_new_order" Hook, can this help to trigger after visitor completes checkout?

If you can tweak it, my offer is I will submit a new $25 question for your new answer. Please respond.

Thanks.


Reigel Gallarde comments:

It will not make much difference... The page will still need to load/connect to the server for a time interval... example, for the page to know that there's a new order, the page needs to load a page (ajax) to check if there's new order.

I'm currently working on the transition..


email889 comments:

are you sure??
so, there is no way when user complete checkout, then trigger the shop order list to LOAD rather than shop_order list do the checking.

Thanks..


Reigel Gallarde comments:

yes I'm positive.. in order for the page to know that there's a new order, it has to contact the server...


email889 comments:

Just wondering, if you know buddypress, there is activity log showing global users uptodate messages/chats in real-time without reloading page.

This activity log working method is also need to check to the server continuously?


Reigel Gallarde comments:

it is still loading in background, ajax ... but different data type... not html but json...
you can check by using dev tools on google chrome by pressing F12... the page activity is in network tab...


email889 comments:

I need pagination for this loop and to work together with your script.

Split to 10 posts per page, pagination on foot.

Can you add it? I will submit a new $15 question.

Thanks.


Reigel Gallarde comments:

for the transition, this might work if no javascript error...

I have not tried this, but please check.. the new code is here: http://pastebin.com/raw/XibkxsrK

you also need to add css somewhere for this page...

#tblExport tr td {
background-color: #fff;
transition: background-color 4s ease;
}
#tblExport .new td {
background-color: yellow;
}


without this css, the script will not work..


Reigel Gallarde comments:

if with pagination, this code will not work...
I answered earlier basing on your loop...


email889 comments:

Will this work If I add lazy load?


email889 comments:

Will this be able to work if use together with something like http://jscroll.com/

I just need your answer then I will mark this as solved. Thanks.


Reigel Gallarde comments:

yes... this might work depending on how you'll implement a lazy load...

jscroll on the other hand is much like a paginated page cut into one... where if you scroll down, the next page will be added at the bottom... it seems not applicable in what you are doing now... you are loading new orders... so I'm not sure if this will work...

2016-11-13

mod mi answers:

1. Your custom single template should now have the following, including the loop with header and footer:

<?php get_header(); ?>
<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 $args = array(
'post_type' =>'shop_order',
'post_status' => array_keys( wc_get_order_statuses() ),
'posts_per_page' => -1,
'order' => 'DESC',
'item_meta' => array (
'_sku' => 'ABCD',
)
);

$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; ?>
</tbody>
</table>
<?php get_footer(); ?>

2. Next create a .php file in your theme’s folder and name it loopOrder.php and paste the following. It's actually the wp_query loop and the body contents.

Notice: Please notice that on your query args you have 'post_status' => 'publish'. I have the latest woocommerce version and it throws me a notice that this is deprecated for querying orders and it now works with order status ('complete','pending' etc).In my code I used the recommended function to get all order statuses. This way if an order's status changes it will be updated on your custom page too.

<?php

define('WP_USE_THEMES', false);
require_once('../../../wp-load.php');

//Add this function to color code the rows depending on the order's status
function colorCodedOrders($orderStatus) {
if ($orderStatus == 'processing') {
echo 'style="color:green"';
}
if ($orderStatus == 'pending payment' || $orderStatus == 'on-hold') {
echo 'style="color:orange"';
}
if ($orderStatus == 'failed' || $orderStatus == 'cancelled' || $orderStatus == 'refunded') {
echo 'style="color:red"';
}
if ($orderStatus == 'completed') {
echo 'style="color:blue"';
}
}

$args = array(
'post_type' =>'shop_order',
'post_status' => array_keys( wc_get_order_statuses() ),
'posts_per_page' => -1,
'order' => 'DESC',
'item_meta' => array (
'_sku' => 'ABCD',
)
);

$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$order_id = $loop->post->ID;
$order = new WC_Order($order_id);
?>

// colorCodedOrders function called for every row
<tr <?php if ($order->status) : colorCodedOrders($order->status); endif; ?>>
<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(); ?>


3.Next in your main .js script inside the document ready function paste the following, replacing “YOUR-DOMAIN” with your actual domain and “YOUR-THEME” with your actual theme folder name.

function update_orders_ajax() {
var $content = $("#export-pla");
$.ajax({
url: 'http://YOUR-DOMAIN/wp-content/themes/YOUR-THEME/loopOrder.php',
type: "get",
dataType: "html",
cache: true,
success: function(data){
$data = $(data);
$content.empty().append($data);
},
error: function(jqXHR, textStatus, errorThrown) {
alert(jqXHR + " :: " + textStatus + " :: " + errorThrown);
},
complete: function() {
// Schedule the next request when the current one's complete
setTimeout(update_orders_ajax, 10000);
}
});
}

if ($('#tblExport').length) {
update_orders_ajax();
}

The function will fire whenever it finds the table with id "tblExport" in the page loaded. You can adjust the the request interval from the setTimeout part.


email889 comments:

Hi, thank you for the respond.

I am using this codes on the single custom page. Are you able to revise the code and send me with all code that I can put on a same page or single.php file.

Thank you.


mod mi comments:

I updated my answer. You can paste the code from step 1 in your custom single template. Regards


email889 comments:

I am putting All 1,2,3 codes in onepage.php
How to replace ?? url: 'http://YOUR-DOMAIN/wp-content/themes/YOUR-THEME/loopOrder.php',
there will be no loopOrder.php


mod mi comments:

Code on step 1 goes in your onepage.php
Code on step 2 goes in loopOrder.php. You have to create this file in your theme's folder in order for the js script to retrieve and refresh your data on your page. loopOrder.php is not a theme file accessible on the front end like single.php. It is used by the script to refresh the data.
Code on step 3 goes in your main .js functions that you include in your theme. It has to be inside a document ready function.

Let me know if you will need further assistance
Regards.


mod mi comments:

For the url in the .js script you have to replace the 'YOUR-DOMAIN' part with your actual domain 'http://example.com' and 'YOUR-THEME' part with your theme's folder name 'example-theme'


email889 comments:

I tried all those setups and returned a blank page.


mod mi comments:

Could you please let me know the full name you are using for your custom page php? How do you access that page?


email889 comments:

i use a php to shortcode converter and place shortcode on the page.


mod mi comments:

So you are using a custom page.php template for a specific page. Skip the shortcode and try this: Create a new page on the wp-admin and name it Order List, leave the content blank and publish it. In your theme's folder create a file page-order-list.php file and paste the code from step 1. Now when you visit http://YOUR-DOMAIN/order-list/ the content should load. Let me know how this went


mod mi comments:

Have you tried this?

2016-11-13

Hariprasad Vijayan answers:

Hi there,

Add following script to bottom of your page.
<script type="text/javascript" >
jQuery(document).ready(function($) {
var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>";
setInterval(function() {
var data = {
'action': 'shop_order_update',
};
$.post(ajaxurl, data, function(response) {
$('#export-pla').html(response)
});

}, 15 * 1000); // 15 * 1000 milsec ie, refreshes in every 15 sec.
});
</script>

Add following code to your functions.php of theme.


add_action( 'wp_ajax_shop_order_update', 'shop_order_update_callback' );
add_action( 'wp_ajax_nopriv_shop_order_update', 'shop_order_update_callback' );
function shop_order_update_callback() {
$args = array(
'post_type' =>'shop_order',
'post_status' => 'publish',
'posts_per_page' => -1,
'order' => 'DESC',
'item_meta' => array (
'_sku' => 'ABCD',
)
);
$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();

wp_die(); // this is required to terminate immediately and return a proper response
}

Code for your custom page http://pasted.co/898673d8
Code for your functions.php http://pasted.co/52edd805

Don't remove current code from your functions.php, just add this code too.

Hope it works,

Regards,
Hari


email889 comments:

Hi, thank you for the respond.

I am using this codes on the single custom page. Are you able to revise the code and send me with all code that I can put on a same page or single.php file.

Thank you.


email889 comments:

I tested putting all your codes on my custom page "OrderList.php". First page visit, all orders loaded, after refresh, body table empty, showing '0' zero.


Hariprasad Vijayan comments:

Hi there,

You can't use like that.

Okay. I assume the path of OrderList.php is YORU-SITE.com/wp-content/themes/YOUR-THEME/OrderList.php', let me know if its not correct.

Use following code in OrderList.php

<?php if($_POST && $_POST['process'] == 'shop_order_update'){
define('WP_USE_THEMES', false);
require_once('../../../wp-load.php');
$args = array(
'post_type' =>'shop_order',
'post_status' => 'publish',
'posts_per_page' => -1,
'order' => 'DESC',
'item_meta' => array (
'_sku' => 'ABCD',
)
);
$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();

die();
}else{
$args = array(
'post_type' =>'shop_order',
'post_status' => 'publish',
'posts_per_page' => -1,
'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>
<script type="text/javascript" >
jQuery(document).ready(function($) {
var ajaxurl = "<?php echo get_bloginfo( 'template_url' ); ?>/OrderList.php";
setInterval(function() {
var data = {
'process': 'shop_order_update',
};
$.post(ajaxurl, data, function(response) {
$('#export-pla').html(response)
});
}, 15 * 1000); // 15 * 1000 milsec ie, refreshes in every 15 sec.
});
</script>
<?php } ?>

http://pasted.co/dda1b89b

Its working on my end, Let me know after checking it.

Regards,
Hariprasad


email889 comments:

Fatal error: Call to undefined function _e() in /home/foodable/public_html/wp-content/themes/x-child/OrderList.php on line 65


Hariprasad Vijayan comments:

Change code to this,

<?php if($_POST && $_POST['process'] == 'shop_order_update'){
define('WP_USE_THEMES', false);
require_once('../../../wp-load.php');
$args = array(
'post_type' =>'shop_order',
'post_status' => 'publish',
'posts_per_page' => -1,
'order' => 'DESC',
'item_meta' => array (
'_sku' => 'ABCD',
)
);
$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();

die();
}else{
$args = array(
'post_type' =>'shop_order',
'post_status' => 'publish',
'posts_per_page' => -1,
'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>
<script type="text/javascript" >
jQuery(document).ready(function($) {
var ajaxurl = "<?php echo get_stylesheet_directory_uri(); ?>/OrderList.php";
setInterval(function() {
var data = {
'process': 'shop_order_update',
};
$.post(ajaxurl, data, function(response) {
$('#export-pla').html(response)
});
}, 15 * 1000); // 15 * 1000 milsec ie, refreshes in every 15 sec.
});
</script>
<?php } ?>


email889 comments:

same error

Fatal error: Call to undefined function _e() in /home/foodable/public_html/wp-content/themes/x-child/OrderList.php on line 65


Hariprasad Vijayan comments:

It might be related to file path issue, the code works on my end in child theme too.
Better way is use the first method, its standard WordPress way to achieve this.

2016-11-14

Arnav Joy answers:

Hi ,
Can you show me your site ?