Extend Woocommerce rest api routes fails

While I'm trying to extend Woocommerce Rest-API routes with a custom one I face the following problem. I have the following class which tries to hook inside Woocommerce API

class API_LOADER
{
public function init()
        {
            add_action( 'woocommerce_api_loaded', array( $this, 'load' ) );
        }
        public function load()
        {
            //This method will be not called
            require_once plugin_dir_path( __FILE__ ).'wc-api-custom.php';
            add_filter( 'woocommerce_api_classes', array( $this, 'register' ) );
        }
} 

but woocommerce_api_loaded will not trigger any callback.

What I do wrong in this case

Topic woocommerce-offtopic callbacks rest-api hooks customization Wordpress

Category Web


What if in your register_rest_route() call you can pass it the permission_callback option:

'permission_callback' => function () {
  return current_user_can('customer');
  // OR
  return current_user_can('shop_manager');
}

That way you are sure that you are dealing with a logged in Woocommerce user??

These are the two roles that Woocommerce is adding to your site. https://docs.woocommerce.com/document/roles-capabilities/

I know it's not answering your question directly, but I hope this helps! If I am way off, I can take the answer down.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.