-1

I'm trying to access users purchase information from my wordpress admin plugin so that I can summarise orders e.g:

  • Product name
  • Custom data (in my case text associated with the product)
  • When it was bought
  • How much they paid

It's mostly the information you can find on the "Account" > "Orders" page when the user is logged in.

I've looked through the woocommerce tables but can't find this information.

Can you suggest which tables I can query to pull together the information I'm looking for above?

John Smith
  • 465
  • 1
  • 4
  • 18

1 Answers1

0

The orders are stored at the wp_posts table with a 'shop_order' custom post type. You can simply use the woocommerce function like this.

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

/* Loop each WC_Order object */
foreach( $woo_orders $order ){

  /* Get the ID */
  echo $order->get_id();

  /* Get the status */
  echo $order->get_status(); // The status
}

Or use the normal wordpress loop:

$loop = new WP_Query( array(
   'post_type'         => 'shop_order',
   'posts_per_page'    => -1,
   'post_status'       =>  'wc-ywraq-new' //will get the new order
) );

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

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

    // The object from WC_Order find the reference in woocommerce docs
    $order = wc_get_order($loop->post->ID);

  endwhile;

  wp_reset_postdata(); // always

endif;

Here's the reference from github: https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query

Mel
  • 858
  • 8
  • 15