Woocommerce cURL api to get json in php

I want to use the Woocommerce REST API to get json data using PHP. How will i get that?

The cURL code is :

Read More
curl https://example.com/wc-api/v3/products 
-u consumer_key:consumer_secret

Node.js returns json but php api isn’t? Is there php api to return json data?

Find documentation for Woocommerce API here

Related posts

2 comments

  1. After getting data in the form of PHP Arrays just convert it into JSON:

    $result = json_encode($returned_array);
    
  2. For PHP, You got to use WooCommerce REST API PHP Client Library

    Here is an example

    $products = array();
    try {
        $client = new WC_API_Client( store_url, consumer_key, consumer_secret, $options );
    
        if (isset($_POST['category_id'])) {
            $category_id = $_POST['category_id'];
            $products = $client->products->get_categories($category_id);
        }
    } catch ( WC_API_Client_Exception $e ) {
    
        $error_msg = $e->getMessage() . PHP_EOL;
        // echo $e->getCode() . PHP_EOL;
    }
    
    $response = array();
    
    if ($products) {
        $response['error'] = false;
        $response['data'] = $products;
    } else {
        $response['error'] = true;
        $response['message'] = $error_msg;
    }
    
    echo json_encode($response);
    

Comments are closed.