• Resolved diegpl

    (@diegpl)


    W3 Total Cache is not updating product and shopping page to update stock after purchasing. How can I prevent that without disabling the cache? Tks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • josem3748

    (@josem3748)

    Hi there, same here.

    To be sure, I’ve tried with a clean installation with only:

    Woocommerce
    W3 Cache
    Storefront theme

    Last versions of each to this day (26/02/2023)

    For W3 I used default configuration with Page Cache activated only. I’ve tried Disk Basic and Disk Enhanced and in every test was the same.

    Page cache is not flushing after a purchase.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @diegpl @josem3748

    Thank you for reaching out and I am happy to assist you with this.

    These are changed via the Woo API and do not trigger the cache purge. What you can do is create a custom call to purge individual posts /URLs by calling w3tc_flush_url($url) or w3tc_flush_post( $post_id )

    Also, please check the woocomerce settings to see if the stock can use ajax to bypass the cache.

    Thanks!

    josem3748

    (@josem3748)

    Hi again, thank you for your reply.

    I’m adding this to my functions.php:

    add_action( 'woocommerce_product_set_stock', 'w3tc_flush_all_custom', 999 );
    add_action( 'woocommerce_variation_set_stock', 'w3tc_flush_all_custom', 999 );
    
    function w3tc_flush_all_custom() {
        w3tc_flush_all();
    }

    If you don’t mind me to ask, do you plan to add something to your plugin to solve this issue in the future?

    Thanks again.

    Thread Starter diegpl

    (@diegpl)

    hmmm @josem3748 solution seem to be good, but how would it be for wpms, pls? N could u add that on ur plugin? Bcz if it can be dond like that. It does not look like woo plugin needs to change something on their side…

    Thread Starter diegpl

    (@diegpl)

    add_action( 'woocommerce_product_set_stock', 'flush_shopping_product_cache', 999 );add_action( 'woocommerce_variation_set_stock', 'flush_shopping_product_cache', 999 );function flush_shopping_product_cache() { if ( function_exists( 'is_multisite' ) && is_multisite() ) { global $blog_id; $blog_id_before = get_current_blog_id(); switch_to_blog( $blog_id ); w3tc_flush_post( get_option( 'woocommerce_shop_page_id' ) ); w3tc_flush_post( get_option( 'woocommerce_cart_page_id' ) ); restore_current_blog(); } else { w3tc_flush_post( get_option( 'woocommerce_shop_page_id' ) ); w3tc_flush_post( get_option( 'woocommerce_cart_page_id' ) ); }}function w3tc_flush_post( $post_id ) { if ( function_exists( 'w3tc_pgcache_flush_post' ) ) { w3tc_pgcache_flush_post( $post_id ); } elseif ( function_exists( 'w3tc_flush_post' ) ) { w3tc_flush_post( $post_id ); }}

    Is this code good enough to be implemented in your plugin @vmarko ? ??

    • This reply was modified 2 years ago by diegpl.
    • This reply was modified 2 years ago by diegpl.
    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @diegpl @josem3748

    Thank you for your feedback.
    We are working on a lot of new improvements for the future releases, and I’ll bring this to the team for a discussion.

    Thanks!

    Thread Starter diegpl

    (@diegpl)

    My code did not work and there are many clients complaining yet. @vmarko would u know a code I could use that work? Tks! ??

    Thread Starter diegpl

    (@diegpl)

    This code worked. Pls, is there something wrong in it? Tks! ??

    // Flush cache on order completion function flush_cache_on_order_complete( $order_id ) { // Get the order object $order = wc_get_order( $order_id ); // Get the products in the order $products = $order->get_items(); // Loop through the products foreach ( $products as $product ) { // Get the product ID $product_id = $product->get_product_id(); // Flush cache for the purchased product page if ( function_exists( 'w3tc_flush_post' ) ) { w3tc_flush_post( $product_id ); } } // Flush cache for the shopping page if ( function_exists( 'w3tc_flush_post' ) ) { w3tc_flush_post( get_option( 'woocommerce_shop_page_id' ) ); w3tc_flush_post( get_option( 'woocommerce_cart_page_id' ) ); } } add_action( 'woocommerce_thankyou', 'flush_cache_on_order_complete', 10, 1 );

    Thread Starter diegpl

    (@diegpl)

    So, is the issue solved in this new version? Tks! ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Does not purge product page after purchase to updade woocommerce stock’ is closed to new replies.