• Resolved mohnas

    (@mohnas)


    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, 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

    (@rockfire)

    Hi @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.