Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
use Automattic\WooCommerce\Client;
class Custom_Endpoints_Woocommerce_API
{
protected function get_client() {
return new Client(
get_site_url(),
'woocommerce_consumer_key',
'woocommerce_consumer_secret',
[
'wp_api' => true,
'version' => 'wc/v1',
]
);
}
public function register_woocommerce_routes() {
register_rest_route( 'customroutes', '/products', array(
'methods' => 'GET',
'callback' => array( $this, 'view_products' )
));
}
public function view_products( WP_REST_Request $request ) {
$woocommerce = $this->get_client();
return $woocommerce->get( 'products/categories' );
}
}
@marekka

This comment has been minimized.

Copy link

marekka commented Feb 19, 2018

Hi. Where to put that file? Woocommerce folder or a theme?

@miun173

This comment has been minimized.

Copy link

miun173 commented Aug 19, 2018

where to place this class ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.