diff --git a/includes/multi-currency/class-settings.php b/includes/multi-currency/class-settings.php index f81cf3ddfa1..0f0c3e64de0 100644 --- a/includes/multi-currency/class-settings.php +++ b/includes/multi-currency/class-settings.php @@ -73,9 +73,13 @@ public function get_sections() { * @return array */ public function get_settings( $current_section = '' ) { + global $hide_save_button; + $settings = []; if ( '' === $current_section ) { + $hide_save_button = true; + $settings = apply_filters( $this->id . '_enabled_currencies_settings', [ @@ -382,11 +386,17 @@ public function save() { // Save all settings through the settings API. \WC_Admin_Settings::save_fields( $this->get_settings( $current_section ) ); - // If the manual rate was blank, or zero, we set it to the automatic rate. - $manual_rate = get_option( $this->id . '_manual_rate_' . $current_section, false ); - if ( ! $manual_rate || 0 >= $manual_rate || '' === $manual_rate ) { - $available_currencies = $this->multi_currency->get_available_currencies(); - update_option( $this->id . '_manual_rate_' . $current_section, $available_currencies[ strtoupper( $current_section ) ]->get_rate() ); + // If we are saving the settings for an individual currency, we have some additional logic. + if ( '' !== $current_section && 'store' !== $current_section ) { + // If the manual rate was blank, or zero, we set it to the automatic rate. + $manual_rate = get_option( $this->id . '_manual_rate_' . $current_section, false ); + if ( ! $manual_rate || 0 >= $manual_rate || '' === $manual_rate ) { + $available_currencies = $this->multi_currency->get_available_currencies(); + $selected_currency = strtoupper( $current_section ); + if ( isset( $available_currencies[ $selected_currency ] ) ) { + update_option( $this->id . '_manual_rate_' . $current_section, $available_currencies[ $selected_currency ]->get_rate() ); + } + } } do_action( 'woocommerce_update_options_' . $this->id );