diff --git a/plugins/woocommerce/changelog/add-track-email-settings b/plugins/woocommerce/changelog/add-track-email-settings new file mode 100644 index 00000000000..46c2823fda5 --- /dev/null +++ b/plugins/woocommerce/changelog/add-track-email-settings @@ -0,0 +1,5 @@ +Significance: patch +Type: add +Comment: Track checkboxes and selects in Settings > Emails settings + + diff --git a/plugins/woocommerce/includes/abstracts/abstract-wc-settings-api.php b/plugins/woocommerce/includes/abstracts/abstract-wc-settings-api.php index 6325594333c..e6a31052ff3 100644 --- a/plugins/woocommerce/includes/abstracts/abstract-wc-settings-api.php +++ b/plugins/woocommerce/includes/abstracts/abstract-wc-settings-api.php @@ -212,6 +212,21 @@ abstract class WC_Settings_API { if ( 'title' !== $this->get_field_type( $field ) ) { try { $this->settings[ $key ] = $this->get_field_value( $key, $field, $post_data ); + if ( 'select' === $field['type'] || 'checkbox' === $field['type'] ) { + /** + * Notify that a non-option setting has been updated. + * + * @since 7.8.0 + */ + do_action( + 'woocommerce_update_non_option_setting', + array( + 'id' => $key, + 'type' => $field['type'], + 'value' => $this->settings[ $key ], + ) + ); + } } catch ( Exception $e ) { $this->add_error( $e->getMessage() ); } @@ -219,8 +234,8 @@ abstract class WC_Settings_API { } $option_key = $this->get_option_key(); - do_action( 'woocommerce_update_option', array( 'id' => $option_key ) ); - return update_option( $option_key, apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings ), 'yes' ); + do_action( 'woocommerce_update_option', array( 'id' => $option_key ) ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment + return update_option( $option_key, apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings ), 'yes' ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment } /** @@ -729,7 +744,7 @@ abstract class WC_Settings_API { 'options' => array(), ); - $data = wp_parse_args( $data, $defaults ); + $data = wp_parse_args( $data, $defaults ); $value = $this->get_option( $key ); ob_start(); diff --git a/plugins/woocommerce/includes/tracks/events/class-wc-settings-tracking.php b/plugins/woocommerce/includes/tracks/events/class-wc-settings-tracking.php index 7f1dde896cc..9daaeff03d8 100644 --- a/plugins/woocommerce/includes/tracks/events/class-wc-settings-tracking.php +++ b/plugins/woocommerce/includes/tracks/events/class-wc-settings-tracking.php @@ -89,13 +89,25 @@ class WC_Settings_Tracking { if ( ! in_array( $option['id'], $this->allowed_options, true ) ) { $this->allowed_options[] = $option['id']; } - if ( 'add' === $option['action'] ) { - $this->added_options[] = $option['id']; - } elseif ( 'delete' === $option['action'] ) { - $this->deleted_options[] = $option['id']; - } elseif ( ! in_array( $option['id'], $this->updated_options, true ) ) { + if ( isset( $option['action'] ) ) { + if ( 'add' === $option['action'] ) { + $this->added_options[] = $option['id']; + } elseif ( 'delete' === $option['action'] ) { + $this->deleted_options[] = $option['id']; + } elseif ( ! in_array( $option['id'], $this->updated_options, true ) ) { + $this->updated_options[] = $option['id']; + } + } elseif ( isset( $option['value'] ) ) { + if ( 'select' === $option['type'] ) { + $this->modified_options[ $option['id'] ] = $option['value']; + + } elseif ( 'checkbox' === $option['type'] ) { + $option_state = 'yes' === $option['value'] ? 'enabled' : 'disabled'; + $this->toggled_options[ $option_state ][] = $option['id']; + } $this->updated_options[] = $option['id']; } + } /**