• Hi,
    I have a problem with your plugin and Woocommerce: Woocommerce shows the stock status on single product pages. If a customer buys the last item available, it usually shows “not in stock” afterwards, but when Cachify is active, it still shos “in stock”. I know there are caching plugins which updat this correctly, could Cachify implement this as well?Otherwise you cannot use it together with Woocommerce…

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi bggg12,
    I did some research into Woocommerce and I think this code snippet should help you:

    add_action( 'woocommerce_product_set_stock_status', 'woocommerce_out_of_stock_cachify', 10, 2 );
    function woocommerce_out_of_stock_cachify( $post_id, $status ) {
        $cache = new Cachify();
        $cache->remove_page_cache_by_post_id( $post_id );
    }

    You can put this code into your child themes functions.php and try it. I think it should work, but I didn’t check it myself. This hook is used in set_stock_status() https://docs.woocommerce.com/wc-apidocs/source-class-WC_Product.html#323-343.

    remove_page_cache_by_post_id() is a function in cachify, which removes the current cache of a specific post. Would be great, if you could confirm if it works or not.

    Thank you for using Cachify 🙂

    David.

    Thread Starter bggg12

    (@bggg12)

    Hello David,
    thank you so much for wanting to help.
    Unfortunately the code did not work – the stock status still shows “in stock”…

    EDIT: Okay, my fault: It does work, but only on the single product pages. On the product category pages(basically the product archive) andthe main shop page it still shows in stock…any way to clear cache for these pages as well inyour function?

    Thank you 🙂

    • This reply was modified 7 years, 5 months ago by bggg12.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problem with Woocommerce stock status’ is closed to new replies.