mercredi 21 novembre 2018

Reading Object from Woocommerce API php

I want to check if the Woocommerce API throws an error when I want to connect to it using PHP. When I var_dump the return I will get:

object(stdClass)#231 (1) { ["errors"]=> object(stdClass)#234 (2) { ["code"]=> string(24) "woocommerce_api_disabled" ["message"]=> string(44) "The WooCommerce API is disabled on this site" } }

So I have to work the first object. $data[1] (Cannot use object of type stdClass as array) The same for $data['error']

 $wc_api = new WC_API_Client($consumer_key, $consumer_secret, $store_url);
 $data = $wc_api->get_index();
 echo($data['errors']);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire