plugin development - WC REST API Error Handling

admin2025-04-19  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
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745054056a282292.html

最新回复(0)