Permalink
Browse files

Improve value retrieval for `total_spent` Custom Attribute

Value should always be padded to 2 decimal places. If the value is
zero, `0.00` should be passed for clarity. If the value ends in a
`0`, the value should be padded to 2 decimal places (e.g., `5.50` not
 `5.5`).
  • Loading branch information...
raamdev committed Sep 9, 2016
1 parent 282cb01 commit 86f8ac436b7f69dab348ab3a0b502284dfd3d121
Showing with 1 addition and 1 deletion.
  1. +1 −1 src/includes/classes/Utils/JsSnippet.php
@@ -113,7 +113,7 @@ protected function customAttributes(): array
'wp_login' => $current_user->user_login,
'wp_user_edit' => admin_url('user-edit.php?user_id='.$current_user->ID),
'available_downloads' => c::clip(implode(', ', $available_downloads), 255),
'total_spent' => !empty(wc_get_customer_total_spent($current_user->ID)) ? (float) wc_get_customer_total_spent($current_user->ID) : 0.00,
'total_spent' => sprintf('%0.2f', (float) wc_get_customer_total_spent($current_user->ID)), // Padded value to 2 decimal places, e.g. 0.00 or 5.50.
'total_orders' => wc_get_customer_order_count($current_user->ID),
'wp_roles' => c::clip(implode(', ', $current_user->roles), 255),

0 comments on commit 86f8ac4

Please sign in to comment.