Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
use Automattic\WooCommerce\Client;
class Custom_Endpoints_Woocommerce_API
protected function get_client() {
return new Client(
'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' );
Copy link

marekka commented Feb 19, 2018

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

Copy link

fahmifan commented Aug 19, 2018

where to place this class ?

Copy link

DMezhenskyi commented May 17, 2019

@anghelalexandra, @miun173, @marekka Did you guys figured out how to use this pease of code? Sry, I'm just very beginner in WP

Copy link

mahmoodb653 commented Dec 31, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment