1. Go to this page and download the library: Download badgerwise/wc-connect 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/ */
badgerwise / wc-connect example snippets
use BadgerWise\WcConnect\WcConnect;
use BadgerWise\WcConnect\Auth\ApplicationPassword;
$wc = new WcConnect(
siteUrl: 'https://store.example.com',
auth: new ApplicationPassword('your-wp-username', 'xxxx xxxx xxxx xxxx xxxx xxxx'),
);
$orders = $wc->get('orders', ['per_page' => 20, 'status' => 'processing']);
use BadgerWise\WcConnect\WcConnect;
use BadgerWise\WcConnect\Auth\ConsumerKeys;
$wc = new WcConnect(
siteUrl: 'https://store.example.com',
auth: new ConsumerKeys('ck_xxxxxxxx', 'cs_xxxxxxxx'),
);
new ConsumerKeys('ck_xxxxxxxx', 'cs_xxxxxxxx', useQueryString: true);
use BadgerWise\WcConnect\Auth\AuthorizationFlow;
$flow = new AuthorizationFlow('https://store.example.com');
// 1. Send the user here (browser / in-app web view).
$url = $flow->buildAuthorizeUrl(
appName: 'My Store App',
successUrl: 'myapp://auth/success', // or an https:// callback
rejectUrl: 'myapp://auth/reject',
);
// 2. The user logs in and approves. WordPress redirects to your success_url
// with site_url, user_login and password in the query string.
// 3. Turn those callback params into ready-to-use auth.
$auth = AuthorizationFlow::fromCallback($_GET); // or your deep-link params
$wc = new WcConnect('https://store.example.com', $auth);
$page = $wc->orders()->list(['per_page' => 20, 'status' => 'processing']);
foreach ($page as $order) {
// ...
}
$page->total; // total matching orders across all pages
$page->totalPages; // total number of pages
$page->page; // 1
$page->hasMorePages(); // bool
$page->nextPage(); // 2, or null on the last page