Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudflare cache purge on purchase #37

Open
FreshLondon opened this issue Nov 9, 2020 · 0 comments
Open

Cloudflare cache purge on purchase #37

FreshLondon opened this issue Nov 9, 2020 · 0 comments

Comments

@FreshLondon
Copy link

FreshLondon commented Nov 9, 2020

Hey folks!

Had an issue where the Cloudflare cache wasn't purging when a product was sold, meaning the inventory could go to 0 and still the item would be listed as 'available' on the site.

I know clearing the entire cache is not ideal for every situation, especially large sites, and maybe you could improve on my below code for other users?

function clean_product_cache_after_order($order_id) {
    try {
        rocket_clean_domain();
        return true;
    } catch (Exception $e) {
        error_log('Cloudflare purge failed during order #' . $order_id, $e->getMessage());
    }
}

// hide or show these as you see fit:
add_action('woocommerce_order_status_pending', __NAMESPACE__ . '\clean_product_cache_after_order');
// add_action( 'woocommerce_order_status_failed', __NAMESPACE__ . '\clean_product_cache_after_order' );
// add_action( 'woocommerce_order_status_on-hold', __NAMESPACE__ . '\clean_product_cache_after_order' );
add_action('woocommerce_order_status_processing', __NAMESPACE__ . '\clean_product_cache_after_order');
add_action('woocommerce_order_status_completed', __NAMESPACE__ . '\clean_product_cache_after_order');
// add_action( 'woocommerce_order_status_refunded', __NAMESPACE__ . '\clean_product_cache_after_order' );
// add_action( 'woocommerce_order_status_cancelled', __NAMESPACE__ . '\clean_product_cache_after_order' );

hope it helps, this works perfectly for me but its only a small site so a full cache clear is not an issue. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant