So to help, here is my full snippet file:
/**
* Register the WooCommerce endpoints so they will be cached.
*/
function wprc_add_wc_endpoints( $allowed_endpoints ) {
if ( ! isset( $allowed_endpoints[ 'wc/v2' ] ) || ! in_array( 'products', $allowed_endpoints[ 'wc/v2' ] ) ) {
$allowed_endpoints[ 'wc/v2' ][] = 'products';
}
return $allowed_endpoints;
}
add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_wc_endpoints', 10, 1);
function wprc_add_cacheable_request_headers( $cacheable_headers ) {
$cacheable_headers['wc/v2/products'] = 'authorization';
return $cacheable_headers;
}
add_filter('wp_rest_cache/cacheable_request_headers', 'wprc_add_cacheable_request_headers', 10, 1);
function wc_determine_object_type( $type, $cache_key, $data, $uri ) {
if ( '/wp-json/wc/v2/products/categories' === substr( $uri, 0, 34 ) ) {
return 'product_cat';
} else if ( '/wp-json/wc/v2/products' === substr( $uri, 0, 23 ) ) {
return 'product';
}
return $type;
}
add_filter( 'wp_rest_cache/determine_object_type', 'wc_determine_object_type', 10, 4 );
function wc_flush_category_caches() {
\WP_REST_Cache_Plugin\Includes\Caching\Caching::get_instance()->delete_cache_by_endpoint( '/wp-json/wc/v2/products/categories', \WP_REST_Cache_Plugin\Includes\Caching\Caching::FLUSH_LOOSE );
}
add_action( 'created_product_cat', 'wc_flush_category_caches', 10 );
add_action( 'edit_product_cat', 'wc_flush_category_caches', 10 );
add_action( 'delete_product_cat', 'wc_flush_category_caches', 10 );
changed from v3 to v2 as all my hits are on v2 apparently. I show nothing in my “Endpoint API caches”