Skip to content

Instantly share code, notes, and snippets.

@anghelalexandra
Created October 12, 2017 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anghelalexandra/29d12185b2c5ed5efeecaa40ac1c9bc5 to your computer and use it in GitHub Desktop.
Save anghelalexandra/29d12185b2c5ed5efeecaa40ac1c9bc5 to your computer and use it in GitHub Desktop.
<?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' );
}
}
@fahmifan
Copy link

where to place this class ?

@DMezhenskyi
Copy link

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

@mahmoodb653
Copy link

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