• Resolved cochii

    (@cochii)


    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 3 years, 1 month ago by cochii.
    • This topic was modified 3 years, 1 month ago by cochii.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Luminus Alabi

    (@luminus)

    Automattic Happiness Engineer

    Hi @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

    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.

    (@rainfallnixfig)

    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.