I'm trying to fetch the last order from my Shopify store through the Shopify API on Wordpress with PHP.
The PHP documentation for Shopify API is pretty limited so I'm having some trouble actually getting the data, any data, to be echoed into my Wordpress page.
I've made my Private App on Shopify and I'm using its credentials in the code below (replaced with brackets for security purposes). The app has read access to everything within the shop. There are recent orders, so that is not the problem.
Here is the code that I'm using to display within the body of my Wordpress page:
<?php
$orders_obj_url = 'https://[my api key]:[my api secret]@[my shopify URL handle].myshopify.com/admin/orders.json';
$orders_content = @file_get_contents( $orders_obj_url );
$orders_json = json_decode( $orders_content, true );
$orders = $orders_json['orders'];
echo $orders;
?>
The code above is simply attempting to get the raw array to be outputted onto my page. It currently outputs nothing.
Past this, I'd like to get the most recent order object in the JSON array and only output that one.
There's probably a painfully obvious error in my code or implementation, I've just been staring at it too long and need a fresh pair of eyes. Thanks.
First you will get all order list from shopify order api (GET /admin/orders.json).
all order get in array list so get last array from array list and get order id from las t array.then this order id use for get data of last order id and use this api for get specific order data (api for get specific order data :GET /admin/orders/#{order_id}.json)