Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter libca1993

    (@libca1993)

    Hi @rockfire

    I also tried to clear cache using \WP_REST_Cache_Plugin\Includes\Caching\Caching::get_instance()->delete_related_caches( $post_id, $object_type );

    Can you please provide me with and an example i’m falling to understand how use it. A sample code might help alot

    Thread Starter libca1993

    (@libca1993)

    Hi @rockfire

    So for the viriable and simple should classify them as product?

    Thread Starter libca1993

    (@libca1993)

    Hi

    Thank you for your response,

    I have tried to modify the object type to product but at this moment i didn’t modify for ‘product’ on object type is coming as simple or variable, But when i try to update a product the cache for that product is not being cleared.

    is there anything i need todo?

    here is the screen shot Screen Shoot

    /**
     * Register endpoints so they will be cached.
     */
    function wprc_add_wc_endpoints( $allowed_endpoints ) {
        if ( ! isset( $allowed_endpoints[ 'wc/v3' ] ) || ! in_array( 'products', $allowed_endpoints[ 'wc/v3' ] ) ) {
            $allowed_endpoints[ 'wc/v3' ][] = 'products';
        }
        return $allowed_endpoints;
    }
    add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_wc_endpoints', 10, 1);
    
    function wprc_add_v2_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_v2_wc_endpoints', 10, 1);
    
    function wprc_add_cacheable_request_headers( $cacheable_headers ) {
        $cacheable_headers['wc/v3/products'] = 'Authorization';
        return $cacheable_headers;
    }
    add_filter('wp_rest_cache/cacheable_request_headers', 'wprc_add_cacheable_request_headers', 10, 1);
    
    function wprc_v2_add_cacheable_request_headers( $cacheable_headers ) {
        $cacheable_headers['wc/v2/products'] = 'Authorization';
        return $cacheable_headers;
    }
    add_filter('wp_rest_cache/cacheable_request_headers', 'wprc_v2_add_cacheable_request_headers', 10, 1);
    
    function flutter_multi_vendor_wc_endpoints( $allowed_endpoints ) {
        if ( ! isset( $allowed_endpoints[ 'api/flutter_multi_vendor' ] ) || ! in_array( 'product', $allowed_endpoints[ 'api/flutter_multi_vendor' ] ) ) {
            $allowed_endpoints[ 'api/flutter_multi_vendor' ][] = 'product';
        }
        return $allowed_endpoints;
    }
    add_filter( 'wp_rest_cache/allowed_endpoints', 'flutter_multi_vendor_wc_endpoints', 10, 1);
    // Determine object type
    function wc_determine_object_type( $type, $cache_key, $data, $uri ) {
    
        if(strstr($uri,'category')){
            return 'category';
        }
        else if(strstr($uri, 'variations')){
            return 'variations';
        }else if ('/wp-json/wc/v2/products/attributes' === substr( $uri, 0, 34)){
            return 'attritubes';
        } else if  (strstr($uri, 'tags')){
            return 'tags';
        }else if ('/wp-json/api/flutter_multi_vendor/product-categories' === substr( $uri, 0, 52 ) ){
             return 'category';
         }
        return $type;
    }
    add_filter( 'wp_rest_cache/determine_object_type', 'wc_determine_object_type', 10, 4 );
    • This reply was modified 3 years, 7 months ago by libca1993.
Viewing 3 replies - 1 through 3 (of 3 total)