@@ -30,6 +30,8 @@ class MultiCurrency {
3030 const CURRENCY_META_KEY = 'wcpay_currency ' ;
3131 const FILTER_PREFIX = 'wcpay_multi_currency_ ' ;
3232 const CUSTOMER_CURRENCIES_KEY = 'wcpay_multi_currency_stored_customer_currencies ' ;
33+ const RENDERING_MODE_SPEED = 'speed ' ;
34+ const RENDERING_MODE_CACHE = 'cache ' ;
3335
3436 /**
3537 * The plugin's ID.
@@ -1041,6 +1043,25 @@ public function is_using_storefront_switcher(): bool {
10411043 return 'yes ' === get_option ( $ this ->id . '_enable_storefront_switcher ' , 'no ' );
10421044 }
10431045
1046+ /**
1047+ * Gets the rendering mode for multi-currency prices.
1048+ *
1049+ * @return string One of 'speed' or 'cache'.
1050+ */
1051+ public function get_rendering_mode (): string {
1052+ return get_option ( 'wcpay_multi_currency_rendering_mode ' , self ::RENDERING_MODE_SPEED );
1053+ }
1054+
1055+ /**
1056+ * Checks if the cache-optimized rendering mode is active.
1057+ *
1058+ * @return bool
1059+ */
1060+ public function is_cache_optimized_mode (): bool {
1061+ return \WC_Payments_Features::is_mc_cache_optimized_enabled ()
1062+ && self ::RENDERING_MODE_CACHE === $ this ->get_rendering_mode ();
1063+ }
1064+
10441065 /**
10451066 * Gets the store settings.
10461067 *
@@ -1050,6 +1071,8 @@ public function get_settings() {
10501071 return [
10511072 $ this ->id . '_enable_auto_currency ' => $ this ->is_using_auto_currency_switching (),
10521073 $ this ->id . '_enable_storefront_switcher ' => $ this ->is_using_storefront_switcher (),
1074+ 'wcpay_multi_currency_rendering_mode ' => $ this ->get_rendering_mode (),
1075+ 'is_cache_optimized_feature_enabled ' => \WC_Payments_Features::is_mc_cache_optimized_enabled (),
10531076 'site_theme ' => wp_get_theme ()->get ( 'Name ' ),
10541077 'date_format ' => esc_attr ( get_option ( 'date_format ' , 'F j, Y ' ) ),
10551078 'time_format ' => esc_attr ( get_option ( 'time_format ' , 'g:i a ' ) ),
@@ -1068,12 +1091,23 @@ public function update_settings( $params ) {
10681091 $ updateable_options = [
10691092 'wcpay_multi_currency_enable_auto_currency ' ,
10701093 'wcpay_multi_currency_enable_storefront_switcher ' ,
1094+ 'wcpay_multi_currency_rendering_mode ' ,
10711095 ];
10721096
10731097 foreach ( $ updateable_options as $ key ) {
1074- if ( isset ( $ params [ $ key ] ) ) {
1075- update_option ( $ key , sanitize_text_field ( $ params [ $ key ] ) ) ;
1098+ if ( ! isset ( $ params [ $ key ] ) ) {
1099+ continue ;
10761100 }
1101+
1102+ $ value = sanitize_text_field ( $ params [ $ key ] );
1103+
1104+ // Validate rendering mode to only accept known values.
1105+ if ( 'wcpay_multi_currency_rendering_mode ' === $ key
1106+ && ! in_array ( $ value , [ self ::RENDERING_MODE_SPEED , self ::RENDERING_MODE_CACHE ], true ) ) {
1107+ continue ;
1108+ }
1109+
1110+ update_option ( $ key , $ value );
10771111 }
10781112 }
10791113
0 commit comments