From 42d161750a3db0375a826384b8f72eb58846d622 Mon Sep 17 00:00:00 2001 From: Daniel Mallory Date: Tue, 15 Jun 2021 10:43:58 +0100 Subject: [PATCH 1/3] Added logic to only try and update the manual rate if we aren't on the main multi-currency page --- includes/multi-currency/class-settings.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/includes/multi-currency/class-settings.php b/includes/multi-currency/class-settings.php index f81cf3ddfa1..edcce5f0038 100644 --- a/includes/multi-currency/class-settings.php +++ b/includes/multi-currency/class-settings.php @@ -382,11 +382,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 ) { + // 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 ); From 71c83b4bc68801a68317e9aa0fab2b9a8f4ceb14 Mon Sep 17 00:00:00 2001 From: Daniel Mallory Date: Tue, 15 Jun 2021 13:53:08 +0100 Subject: [PATCH 2/3] Hide the save button on the main enabled currencies page --- includes/multi-currency/class-settings.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/multi-currency/class-settings.php b/includes/multi-currency/class-settings.php index edcce5f0038..2625c07fdb1 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', [ From ccbeab3ff528540b1f30b5eb22a11749a2883f65 Mon Sep 17 00:00:00 2001 From: Daniel Mallory Date: Tue, 15 Jun 2021 15:51:58 +0100 Subject: [PATCH 3/3] Adding check to make sure we aren't in the store section --- includes/multi-currency/class-settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/multi-currency/class-settings.php b/includes/multi-currency/class-settings.php index 2625c07fdb1..0f0c3e64de0 100644 --- a/includes/multi-currency/class-settings.php +++ b/includes/multi-currency/class-settings.php @@ -387,7 +387,7 @@ public function save() { \WC_Admin_Settings::save_fields( $this->get_settings( $current_section ) ); // If we are saving the settings for an individual currency, we have some additional logic. - if ( '' !== $current_section ) { + 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 ) {