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/ */

    

mindsize / laravel5-woocommerce example snippets


WC_STORE_URL=http://example.org
WC_CONSUMER_KEY=ck_your-consumer-key
WC_CONSUMER_SECRET=cs_your-consumer-secret
WC_VERIFY_SSL=false
WC_VERSION=v1
WC_WP_API=true
WC_WP_QUERY_STRING_AUTH=false
WC_WP_TIMEOUT=15

use WooCommerce;

return WooCommerce::get('');

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;

$data = [
    'product' => [
        'title' => 'Updated title'
    ]
];

return WooCommerce::put('products/1', $data);

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']
 bash
php artisan vendor:publish --provider="Mindsize\WooCommerce\ServiceProvider"