Skip to main content

Invalidate derived caches when the license server publishes new pricing

Free Beginner Since v1.0.0

LicensePricingFetcher::refresh() fires benecaster_pricing_data_changed( array $pricing, ?string $previous_updated_at, string $new_updated_at ) whenever the freshly-fetched updated_at differs from the cached value. Use this to invalidate any pricing-derived cache (UI snapshots, calculator inputs, plan-comparison tables) without polling. The bundle’s individual_total and discount_pct are dynamic on the server — always read them from LicenseManager::get_bundle() rather than summing visible add-on prices locally.

Code

<?php
add_action( 'benecaster_pricing_data_changed', function ( array $pricing, ?string $previous, string $next ): void {
    // Force a rebuild of any cached plan-comparison snapshot when prices move.
    delete_transient( 'my_plan_comparison_html' );
}, 10, 3 );

Hooks Used