Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for fatal error when saving changes on Multi-Currency page #2182

Merged
merged 5 commits into from
Jun 16, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions includes/multi-currency/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
[
Expand Down Expand Up @@ -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 ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soon we'll also introduce the store section. Do you think we should also include a check for it here in case we forget to do it when enabling it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Updated in ccbeab3.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! :shipit:

// 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 );
Expand Down