File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
WooCommerce/Classes/ViewRelated/Dashboard/Factories Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,18 @@ final class StatsV4DataHelper {
3737 }
3838 }
3939
40+ /// Creates the text to display for the average order value.
41+ ///
42+ static func createAverageOrderValueText( orderStatsData: OrderStatsData , currencyFormatter: CurrencyFormatter , currencyCode: String ) -> String {
43+ if let value = averageOrderValue ( orderStats: orderStatsData. stats) {
44+ // If order value is an integer, no decimal points are shown.
45+ let numberOfDecimals : Int ? = value. isInteger ? 0 : nil
46+ return currencyFormatter. formatAmount ( value, with: currencyCode, numberOfDecimals: numberOfDecimals) ?? String ( )
47+ } else {
48+ return Constants . placeholderText
49+ }
50+ }
51+
4052 // MARK: Views and Visitors Stats
4153
4254 /// Creates the text to display for the visitor count.
@@ -104,6 +116,16 @@ private extension StatsV4DataHelper {
104116 }
105117 }
106118
119+ /// Retrieves the average order value for the provided order stats.
120+ ///
121+ static func averageOrderValue( orderStats: OrderStatsV4 ? ) -> Decimal ? {
122+ if let orderStats {
123+ return orderStats. totals. averageOrderValue
124+ } else {
125+ return nil
126+ }
127+ }
128+
107129 /// Retrieves the total revenue from the provided order stats and, optionally, a specific interval.
108130 ///
109131 static func totalRevenue( at selectedIndex: Int ? , orderStats: OrderStatsV4 ? , orderStatsIntervals: [ OrderStatsV4Interval ] ) -> Decimal ? {
You can’t perform that action at this time.
0 commit comments