1

I'm looking for a way o create my own web interface to view and manage WordPress/WooCommerce orders.

The idea is that I do not want to use the WP backend, this is for a small takeaway shop that wants to simply be able to view just the orders and accept them and then press a button to mark orders as complete.

I have ha da quick look into it and it seems that WooCommerce provides an API to hook into. I would prefer to build this using PHP and have found this https://packagist.org/packages/woothemes/woocommerce-api

This supposedly allows me to interact with the woocommerce using PHP I'm just not 100 sure where to start. I guess my question is:

Is this actually possible? It should simply display the orders on a webpage as they come in (some form of auto refresh) and allow me to mark orders as complete or not.

and How would I start this?

Any help would be appreciated.

Edit: Ok so after having a quick crack at this I have actually got an example page up and running, connected to my WooCommerce site and it displays the orders.

I now need to figure out how to only show the relevant information as this is an example of want it prints out right now

stdClass Object ( [orders] => Array ( [0] => stdClass Object ( [id] => 16 [order_number] => 16 [created_at] => 2015-07-29T17:24:00Z [updated_at] => 2015-07-29T17:24:00Z [completed_at] => 2015-07-29T16:24:00Z [status] => processing [currency] => GBP [total] => 0.00 [subtotal] => 0.00 [total_line_items_quantity] => 1 [total_tax] => 0.00 [total_shipping] => 0.00 [cart_tax] => 0.00 [shipping_tax] => 0.00 [total_discount] => 0.00 [shipping_methods] => [payment_details] => stdClass Object ( [method_id] => [method_title] => [paid] => 1 ) [billing_address] => stdClass Object ( [first_name] => Chris [last_name] => Last name [company] => [address_1] => number [address_2] => [city] => town [state] => [postcode] => post code [country] => GB [email] => email [phone] => phone # ) [shipping_address] => stdClass Object ( [first_name] =

Any idea how I can extract on the relevant information. To get this data I used:

print_r( $client->orders->get() );

Apologies for the ignorance I am new to this JSON stuff :)

Ok so edit number 3 here:

As before I can view orders by using this:

print_r( $client->orders->get() );

So I thought maybe I could use a foreach loop to iterate through the array. But this doesn't seem to work.

 $orders = $client->orders->get();

    foreach ($orders as $key => $value){

        echo $key . '=' . $value . '</br>';

    }

Any ideas?

Ok so update number 4!

This loop seems to work(ish)

foreach( $orders as $order ) {
      foreach( $order as $value ) {
        echo $value["id"] . '</br>';
        echo $value["status"] . '</br>';
        echo $value["total"] . '</br>';
      }
    }

The loop returns this result: enter image description here

chinds
  • 1,761
  • 4
  • 28
  • 54
  • Yes the WooCommerce API will allow you to view the orders. You should start with the [API documentation](http://docs.woothemes.com/document/woocommerce-rest-api/) and come back when you have a more specific problem. – helgatheviking Jul 29 '15 at 19:55
  • Hi there, thanks for the link to the documentation. As you can see in my edited comment I have now now connected to the store and can view orders. However I am not sure how to view specific order information like just the items orders and the customers email. I can get a specific order by using this: print_r($client->orders->get(16)); I thought I would be able to write something like this to for instance get the order status: print_r($client->orders->get(16, 'status')); – chinds Jul 29 '15 at 20:12
  • [customer orders](http://woothemes.github.io/woocommerce-rest-api-docs/#view-customer-orders) and [view an order](http://woothemes.github.io/woocommerce-rest-api-docs/#view-an-order). I haven't really gotten to play with the API yet, so I would love to see your code when you are finished. – helgatheviking Jul 29 '15 at 20:23
  • Hi there, Having some trouble with this. I cant seem to to be able to pull out just the order status for example. any help from anyone here would be much appreciated I must be doing something silly. – chinds Jul 29 '15 at 20:54

1 Answers1

1

Order status appears to be in the JSON response for view customer orders as a status property in the order object.

Edited to decode the json response.

$json = $client->orders->get();

$orders = json_decode( $json );

foreach( $orders->orders as $order ){
    echo $order->order_number. ' has a status = ' . $order->status. '</br>';
}
helgatheviking
  • 25,596
  • 11
  • 95
  • 152
  • Thanks for your response unfortunately with this code I receive this error Trying to get property of non-object in D:\wamp2\www\woo\example.php on line 51. so it cannot get the order number number or the order status. What I have found so far that works ok to loop like this: foreach( $orders as $order ) { foreach( $order as $value ) { echo $value["id"] . ''; echo $value["status"] . ''; echo $value["total"] . ''; } } Please my updated question for this example – chinds Jul 29 '15 at 21:50
  • Well that error means that `$order` isn't an object. I didn't really test anything. I've gone back and looked at the API docs again and tried out `json_decode`. Check out my edit. – helgatheviking Jul 29 '15 at 23:48
  • Hmmm again thanks for the help. however the json response seems to br bringing in an array and not a string. Warning: json_decode() expects parameter 1 to be string, object given in I think I am going to go with my earlier example and try and work out the kinks from there. Thanks. – chinds Jul 30 '15 at 09:56