Hi this function is working fine in Theme > function.php but when I added this in my custom plugin it is showing 401 error. Why is this happening?
I used your Get shipment Tracking API from this documentation- https://www.zorem.com/docs/woocommerce-advanced-shipment-tracking/rest-api-support/
//CUSTOM TABLE FOR ADVANCED SHIPMENT PLUGIN START//
// add_action( ‘woocommerce_view_order’, ‘get_order_details’, 0 );
// function get_order_details( $order_id ){
// $ch = curl_init();
// $url = ‘https://abc.com/wp-json/wc-ast/v3/orders/’.$order_id.’/shipment-trackings/’;
// $username = ‘ck_992b***************’;
// $password = ‘cs_5288***************’;
// curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
// curl_setopt($ch, CURLOPT_USERPWD, “$username:$password”);
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “GET”);
// curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/json’));
// $res = curl_exec($ch);
// curl_close($ch);
// $json_response = json_decode($res);
// $tracking_provider = $json_response[0]->tracking_provider;
// $tracking_number = $json_response[0]->tracking_number;
// $tracking_link = $json_response[0]->tracking_link;
// $date_shipped = $json_response[0]->date_shipped;
// $date_shipped = date(‘d F Y’, strtotime($date_shipped));
// echo $tracking_provider.'<br>’;
// echo $tracking_number.'<br>’;
// echo $tracking_link.'<br>’;
// echo $date_shipped.'<br>’;
// echo ‘[row style=”collapse” col_style=”solid”]
// [col span__sm=”12″ border=”2px 2px 2px 2px” border_margin=”5px 5px 5px 5px” border_radius=”0″]
// <h3><span data-text-color=”primary”>TRACKING DETAILS</span></h3>
// [divider width=”full” color=”rgb(0, 0, 0)”]
// <p>Courier: ‘.$tracking_provider.'</p>
// <p>Tracking/ AWB Number: ‘.$tracking_number.'</p>
// <p>Dispatched On: ‘.$date_shipped.'</p>
// [/col]
// [/row]
// [gap height=”10px”]
// <p>[button text=”Live track your order” expand=”0″ icon=”icon-map-pin-fill” icon_reveal=”true” link=”‘.$tracking_link.'”]</p>’;
// }