Custom function for post views
Wordpress LScache Plugin: Custom function for post views
Hi, We are using a custom function to update the total_sales every time the product is viewed. When the cache is on the value of total_sales does not update. Wondering if it is possible to update the total_sales post_meta in the below code even when the cache is switched on. add_action( woocommerce_before_single_product, prefix_save_product_views ) function prefix_save_product_views( ) $product_id = get_the_ID() $increment = 1 $current_visit_count = get_post_meta( $product_id, total_sales, true ) $total_visit_count = (int)$current_visit_count + $increment update_post_meta( $product_id, total_sales, $total_visit_count ) I assume you meant every time the product is SOLD , instead of viewed ? if (defined(LSCWP_V)) do_action( litespeed_purge_post, $product_id ) add this to your function ought do it. Thanks. I indeed meant every time a product is viewed. I am using the code i pasted to save product views in the total_sales post meta every time a product is viewed. Will the above code you provided still work and Would Litespeed cache continue to cache product pages after that. then you should make it to be ajax call , since ajax call will not be cached , and you can load it via ajax call on cached page as well otherwise you will need to implement ESI block , which is bit of more complicated than ajax call please check this page Ok. I will try and figure it out.
Do you need help?
We are online almost any time and ready to answer any question. The answer to your question will come faster than it takes you to release the mouse button. Ask A Question