Title: Use woocommerce API inside functions.php
Last modified: January 26, 2022

---

# Use woocommerce API inside functions.php

 *  Resolved [cochii](https://wordpress.org/support/users/cochii/)
 * (@cochii)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/use-woocommerce-api-inside-functions-php/)
 * Hello
    I have a site using woocommerce and other plugins
 * One of the plugins has an API related to Woocommerce (to use the plugin API you
   have to use the woocommerce API, they just added new routes)
    I want to call 
   one of these routes in my functions.php file in a woocommerce hook
 * I tried to do this :
 *     ```
       $autoloader = WP_CONTENT_DIR . '/plugins/woocommerce/vendor/autoload.php';
       if ( is_readable( $autoloader ) ) {
           require_once($autoloader);
       }
       function action() {
           $order = wc_get_order($this_get_id);
           $woocommerce = new \Automattic\WooCommerce\Client(
               'domains',
               'credentials',
               'credentials',
               [
                   'wp_api' => true,
                   'version' => 'wc/v3'
               ]
           );
           $test = $woocommerce->get('customers/989');
           var_dump($test);
           die();
       };
       // add the action
       add_action( 'woocommercehook', 'action', 10, 3 );
       ```
   
 * But I have this error Uncaught Error: Class ‘Automattic\WooCommerce\Client’ not
   found
 * How to use Automattic\WooCommerce\Client inside functions.php please?
    -  This topic was modified 4 years, 4 months ago by [cochii](https://wordpress.org/support/users/cochii/).
    -  This topic was modified 4 years, 4 months ago by [cochii](https://wordpress.org/support/users/cochii/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Luminus Alabi](https://wordpress.org/support/users/luminus/)
 * (@luminus)
 * Automattic Happiness Engineer
 * [4 years, 4 months ago](https://wordpress.org/support/topic/use-woocommerce-api-inside-functions-php/#post-15294451)
 * Hi [@cochii](https://wordpress.org/support/users/cochii/),
 * This isn’t how to use the REST API. The point of a REST API is to allow you to
   communicate with the application from OUTSIDE of it.
 * You can learn more about the WooCommerce REST API and how to use it here – [https://woocommerce.com/document/woocommerce-rest-api](https://woocommerce.com/document/woocommerce-rest-api)
 * If you need information specific to the API of the plugin you’re trying to access,
   you’ll want to speak to the developers of that plugin as they’ll be able to offer
   guidance as to how to interface with their API.
 *  [Mirko P.](https://wordpress.org/support/users/rainfallnixfig/)
 * (@rainfallnixfig)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/use-woocommerce-api-inside-functions-php/#post-15321579)
 * Hi there,
 * We haven’t heard from you in a while, so I’m going to mark this as resolved. 
   Feel free to start a new thread if you have any more questions.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Use woocommerce API inside functions.php’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)

 * 2 replies
 * 3 participants
 * Last reply from: [Mirko P.](https://wordpress.org/support/users/rainfallnixfig/)
 * Last activity: [4 years, 4 months ago](https://wordpress.org/support/topic/use-woocommerce-api-inside-functions-php/#post-15321579)
 * Status: resolved