Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 576 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to query Woocommerce orders on a page

#1
I want to create a page that displays a query from the database to show some order details.

How to display this query on a page?
Reply

#2
As long as it's the last query executed, you can use `$wpdb->last_query` to grab the last query. You'll need to have `define('SAVEQUERIES', true)` in your `wp-config.php` for this
Reply

#3
There is multiple ways to get Woocommerce Orders:

1) Woocommerce has a dedicated function [`wc_get_orders()`][1] that will give you an array of WC_Order objects:

$orders = wc_get_orders( array('numberposts' => -1) );

// Loop through each WC_Order object
foreach( $orders as $order ){
echo $order->get_id() . '<br>'; // The order ID
echo $order->get_status() . '<br>'; // The order status
}

To get the order data see the links below

----------

2) You can also use a Wordpress [`WP_Query`][2]:

$loop = new WP_Query( array(
'post_type' => 'shop_order',
'post_status' => array_keys( wc_get_order_statuses() ),
'posts_per_page' => -1,
) );

// The Wordpress post loop
if ( $loop->have_posts() ):
while ( $loop->have_posts() ) : $loop->the_post();

// The order ID
$order_id = $loop->post->ID;

// Get an instance of the WC_Order Object
$order = wc_get_order($loop->post->ID);

endwhile;

wp_reset_postdata();

endif;

To get the order data see the links below

------

3) You can use a SQL query

global $wpdb;
$results = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}posts WHERE post_type LIKE 'shop_order'");

// Loop through each order post object
foreach( $results as $result ){
$order_id = $result->ID; // The Order ID

// Get an instance of the WC_Order Object
$order = wc_get_order( $result->ID );
}

--------

You will be able to get all order details from the [`WC_Order` object][3] as explained in:

-

[To see links please register here]

-

[To see links please register here]



-------

**Displaying the data as a list in a table**

To display the orders in a list, you should have a look to the woocommerce deprecated template [myaccount/my-orders.php][4] or to [myaccount/orders.php template][5]…

It will give you a model…


[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

[4]:

[To see links please register here]

[5]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through