PHP code example of mindsize / laravel5-woocommerce
1. Go to this page and download the library: Download mindsize/laravel5-woocommerce library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use WooCommerce;
return WooCommerce::get('orders');
use WooCommerce;
$data = [
'status' => 'completed',
'filter' => [
'created_at_min' => '2016-01-14'
]
];
$result = WooCommerce::get('orders', $data);
foreach($result['orders'] as $order)
{
// do something with $order
}
// you can also use array access
$orders = WooCommerce::get('orders', $data)['orders'];
foreach($orders as $order)
{
// do something with $order
}
use WooCommerce;
$data = [
'status' => 'completed',
'after' => '2016-01-14T00:00:00'
]
];
$result = WooCommerce::get('orders', $data);
foreach($result['orders'] as $order)
{
// do something with $order
}
// you can also use array access
$orders = WooCommerce::get('orders', $data)['orders'];
foreach($orders as $order)
{
// do something with $order
}
use WooCommerce;
// assuming we have 474 orders in pur result
// we will request page 5 with 25 results per page
$params = [
'per_page' => 25,
'page' => 5
];
WooCommerce::get('orders', $params);
WooCommerce::totalResults(); // 474
WooCommerce::firstPage(); // 1
WooCommerce::lastPage(); // 19
WooCommerce::currentPage(); // 5
WooCommerce::totalPages(); // 19
WooCommerce::previousPage(); // 4
WooCommerce::nextPage(); // 6
WooCommerce::hasPreviousPage(); // true
WooCommerce::hasNextPage(); // true
WooCommerce::hasNotPreviousPage(); // false
WooCommerce::hasNotNextPage(); // false
use WooCommerce;
// first send a request
WooCommerce::get('orders');
// get the request
WooCommerce::getRequest();
// get the response headers
WooCommerce::getResponse();
// get the total number of results
WooCommerce::getResponse()->getHeaders()['X-WP-Total']