From 39c7201b55fd2731375fd89402a8ef838257632a Mon Sep 17 00:00:00 2001 From: Malith Senaweera <6216000+malithsen@users.noreply.github.com> Date: Thu, 30 Jan 2025 15:10:27 -0600 Subject: [PATCH] Clear styles cache when customizing the theme (#3812) --- .../class-wc-stripe-upe-payment-gateway.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php index 0d48bdcc4..e7ecac406 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -228,6 +228,10 @@ public function __construct() { add_action( 'wc_ajax_wc_stripe_save_appearance', [ $this, 'save_appearance_ajax' ] ); add_filter( 'woocommerce_saved_payment_methods_list', [ $this, 'filter_saved_payment_methods_list' ], 10, 2 ); + + // Add hooks for clearing appearance transients when theme is updated + add_action( 'customize_save_after', [ $this, 'clear_appearance_transients' ] ); + add_action( 'save_post', [ $this, 'clear_appearance_transients_block_theme' ], 10, 2 ); } /** @@ -2823,4 +2827,22 @@ public function save_appearance_ajax() { ); } } + + /** + * Clears the appearance transients when a Block theme is updated or customized. + * This ensures the UPE appearance is regenerated with the new theme colors. + */ + public function clear_appearance_transients_block_theme( $post_id, $post ) { + if ( in_array( $post->post_type, [ 'wp_global_styles' ], true ) ) { + delete_transient( $this->get_appearance_transient_key( true ) ); + } + } + + /** + * Clears the appearance transients when a classic theme is updated or customized. + * This ensures the UPE appearance is regenerated with the new theme colors. + */ + public function clear_appearance_transients() { + delete_transient( $this->get_appearance_transient_key() ); + } }