• Resolved patchyart

    (@patchyart)


    Hi,

    I have the following code to purge the cache of a stock when the product is saved:

    add_action('woocommerce_update_product', 'lscwp_purge_product_update', 10, 2);
    function lscwp_purge_product_update($product_id, $product) {
    if (defined('LSCWP_V')){
    do_action( 'litespeed_purge_post', $product_id );
    }
    }

    Is there a way to do the same when a new review is made on the product?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support qtwrk

    (@qtwrk)

    you can use comment_post hook , e.g.

    add_action('comment_post', ........

    Thread Starter patchyart

    (@patchyart)

    Hi, thank you!

    Something like this? :

    add_action('comment_post', 'lscwp_purge_product_update', 10, 3);
    function lscwp_purge_product_update( $comment_ID, $comment_approved, $commentdata ) {
        
      $comment_post_id = $commentdata['comment_post_ID'];
       if (defined('LSCWP_V')){
            do_action( 'litespeed_purge_post', $comment_post_id );
        }
    }
    Plugin Support qtwrk

    (@qtwrk)

    add_action( 'comment_post', 'get_post_id_on_comment_post', 10, 2 );
    
    function get_post_id_on_comment_post( $comment_ID, $comment_approved ) {
        if ( $comment_approved === '1' ) {
            $post_id = $comment->comment_post_ID;
            if (defined('LSCWP_V')){
                do_action( 'litespeed_purge_post', $post_id );
            }
    }

    maybe this , add check in comment approve status to avoid unneeded purge.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Purge Cache of product on review’ is closed to new replies.