最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - WC REST API Error Handling

programmeradmin0浏览0评论

I am using the WooCommerce Rest API to query the products on a WooCommerce store. The Product ID ($id) is retrieved from the order line items. Some of the old orders in my database have products that have since been deleted from the store.

I would like to catch this error and return "0.0" but the error keeps stopping my script. Please see the section from my script below and the error from the logs. I am using the Exception wrong in this case?

   try {
        $product = $this->client->get('products/' . $id);
    } catch (Exception $e) {
        return 0.0;
    }

ERROR 404 | GET /wp-json/wc/v3/products/0 HTTP/1.0
发布评论

评论列表(0)

  1. 暂无评论