2

I cannot seem to find a way to access the X-WP-TotalPages in the header of the response, I am able to display my orders and everything the way I want to but for the life of me cannot figure out how to get to the headers in the response.

I am using this at the moment;

require($_SERVER["DOCUMENT_ROOT"] . "/vendor/autoload.php");

use Automattic\WooCommerce\Client;

$woocommerce = new Client(
'http://example.com', 
'**********************************', 
'**********************************',
[
    'wp_api' => true,
    'version' => 'wc/v1',
]
);
$endpoint = 'orders';
$options = ['filter[limit]' => '200', 'filter[period]' => 'year', 'filter[order]' => 'ASC', 'status' => 'processing'];

$result = $woocommerce->get($endpoint, $options);

I am pretty certain I need something along the lines of this;

print_r(get_headers($result['X-WP-TotalPages']));

I have tried a number of different variations but just cannot seem to figure it out, any help would be massively appreciated!

Jay the Geek
  • 83
  • 1
  • 11

1 Answers1

7

Came across the same question. Currently you are looking at the result of the response. What you are exactually looking for are the headers of the response. You can get them by

$lastResponse = $woocommerce->http->getResponse();
$headers = $lastResponse->getHeaders();
$totalPages = $headers['X-WP-TotalPages'];
Gerben
  • 143
  • 1
  • 7
  • Thank you, I had found a similar solution, I marked your answer as correct as I had forgotten to come back and answer it myself :) – Jay the Geek Sep 30 '16 at 14:12