Title: Woocommerce Rest API Cache
Last modified: May 14, 2020

---

# Woocommerce Rest API Cache

 *  Resolved [mohnas](https://wordpress.org/support/users/mohnas/)
 * (@mohnas)
 * [6 years ago](https://wordpress.org/support/topic/woocommerce-rest-api-cache/)
 * Hi WP REST Cache Support
 * I registered Woocommerce endpoint to be cached in my code and made its authorization
   same as what you said [here](https://wordpress.org/support/topic/woocommerce-3-2-6-api-cache/),
   and when I checked the endpoint api caches list in the plugin it still didn’t
   add them so what is the solution? (Sample of code added below)
 * Register woocommerce endpoint code sample:
 *     ```
       add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_acf_posts_endpoint', 10, 1);
       function wprc_add_acf_posts_endpoint( $allowed_endpoints ) {
           if ( ! isset( $allowed_endpoints[ 'wc/v3' ] ) || ! in_array( 'shipping/zones/<id>/locations', $allowed_endpoints[ 'wc/v3' ] ) ) {
               $allowed_endpoints[ 'wc/v3' ][] = 'shipping/zones/<id>/locations';
           }
           return $allowed_endpoints;
       ```
   
 * Authorization code sample:
 *     ```
       add_filter('wp_rest_cache/cacheable_request_headers', 'wprc_add_cacheable_request_headers', 10, 1);
       function wprc_add_cacheable_request_headers( $cacheable_headers ) {
           $cacheable_headers['wc/v3/shipping/zones/<id>/locations'] = 'authorization';
       ```
   
 * And regarding the objects what are the object types that I can use and for custom
   endpoint can I use the below code for any object type to flush cache when updated
   or it can only be used for the product_cat object?
 * Thanks 🙂

Viewing 1 replies (of 1 total)

 *  Plugin Author [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * (@rockfire)
 * [6 years ago](https://wordpress.org/support/topic/woocommerce-rest-api-cache/#post-12864932)
 * Hi [@mohnas](https://wordpress.org/support/users/mohnas/)
 * Thank you for using our plugin!
 * The problem with your code is the `<id>` in `'shipping/zones/<id>/locations'``.
   Our plugin does a string comparison and since the actual call will not have`<
   id>` in it, but rather an actual id (so a number) it will not be able to match
   it correctly.
 * At this point I can only advise you to strip the last part: `/<id>/locations`,
   however this will mean all calls starting with `shipping/zones` will be cached.

Viewing 1 replies (of 1 total)

The topic ‘Woocommerce Rest API Cache’ is closed to new replies.

 * ![](https://ps.w.org/wp-rest-cache/assets/icon-256x256.png?rev=3328849)
 * [WP REST Cache](https://wordpress.org/plugins/wp-rest-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-rest-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-rest-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-rest-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-rest-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-rest-cache/reviews/)

## Tags

 * [woocommerce api](https://wordpress.org/support/topic-tag/woocommerce-api/)
 * [WooCommerce REST API](https://wordpress.org/support/topic-tag/woocommerce-rest-api/)

 * 1 reply
 * 2 participants
 * Last reply from: [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * Last activity: [6 years ago](https://wordpress.org/support/topic/woocommerce-rest-api-cache/#post-12864932)
 * Status: resolved