I'm building an online store where the users can send or transfer money. the process is made like buying a normal product trought woocommerce plugin, all this works fine. I'm trying to make a notification in the page top bar when any of the admin set the order to complete or change the status of the order. this mean any order status, "on hold" "Processing" "cancelled". So i'm trying to show a small badge or something like that in the user profile tab and is here where it become a bit tricky for me.
I really dont know woocommerce that deep yet and so i dont know what process or tool can i use to achive this.
My solution was to use the woocommerce REST API to use the process whenever the order status change. so i set up all the library and the necesary code:
require_once( 'lib/woocommerce-api.php' );
$options = array(
'debug' => true,
'return_as_array' => false,
'validate_url' => false,
'timeout' => 30,
'ssl_verify' => false,
);
try {
$client = new WC_API_Client( 'https://mypage.com/', $consumer_key, $consumer_secret, $options );
} catch ( WC_API_Client_Exception $e ) {
echo $e->getMessage() . PHP_EOL;
echo $e->getCode() . PHP_EOL;
if ( $e instanceof WC_API_Client_HTTP_Exception ) {
print_r( $e->get_request() );
print_r( $e->get_response() );
}
}
After that i make the call of any of the process given in the example to test if all is working properly:
print_r( $client->orders->update_status( $order_id, 'pending' ) );
But whe i go to the page where i put any of this code it gives an error "Failed to load resource: the server responded with a status of 500 (Internal Server Error)" and when i try to add the $consumer_key or $consumer_secret the page say this
{"code":"woocommerce_rest_cannot_view","message":"Sorry, you cannot list resources.","data":{"status":401}}
The documentation says how to solve this problem but is not working for me.
I want to know what i'm missing or what i'm doing wrong? is there any other way to made this easier or another tool or function inside woocommerce i can use that tell me when the order change so that way i can make all the process to show the badge in the top bar?