Campaign.php
3 years ago
Current_Traffic.php
3 years ago
Device.php
2 years ago
Geo.php
2 years ago
Page.php
2 years ago
Page_Author_Archive.php
3 years ago
Page_Date_Archive.php
3 years ago
Page_Home.php
3 years ago
Page_Not_Found.php
3 years ago
Page_Post_Type_Archive.php
2 years ago
Page_Search.php
3 years ago
Page_Singular.php
2 years ago
Page_Term_Archive.php
3 years ago
Referrer.php
2 years ago
View_Stats.php
2 years ago
Visitor.php
2 years ago
WooCommerce_Stats.php
3 years ago
WooCommerce_Stats.php
66 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\IAWP\Models; |
| 4 | |
| 5 | trait WooCommerce_Stats |
| 6 | { |
| 7 | protected $wc_orders; |
| 8 | protected $wc_gross_sales; |
| 9 | protected $wc_refunds; |
| 10 | protected $wc_refunded_amount; |
| 11 | public final function wc_orders() : int |
| 12 | { |
| 13 | return $this->wc_orders; |
| 14 | } |
| 15 | public final function wc_gross_sales() |
| 16 | { |
| 17 | return $this->wc_gross_sales; |
| 18 | } |
| 19 | public final function wc_refunds() |
| 20 | { |
| 21 | return $this->wc_refunds; |
| 22 | } |
| 23 | public function wc_refunded_amount() |
| 24 | { |
| 25 | return $this->wc_refunded_amount; |
| 26 | } |
| 27 | public function wc_net_sales() |
| 28 | { |
| 29 | return $this->wc_gross_sales - $this->wc_refunded_amount; |
| 30 | } |
| 31 | public function woocommerce_conversion_rate() |
| 32 | { |
| 33 | $orders = $this->wc_orders(); |
| 34 | $visitors = $this->visitors(); |
| 35 | if ($visitors === 0) { |
| 36 | return 0; |
| 37 | } |
| 38 | return $orders / $visitors * 100; |
| 39 | } |
| 40 | public function woocommerce_earnings_per_visitor() |
| 41 | { |
| 42 | $net_sales = $this->wc_net_sales(); |
| 43 | $visitors = $this->visitors(); |
| 44 | if ($visitors === 0) { |
| 45 | return 0; |
| 46 | } |
| 47 | return $net_sales / $visitors; |
| 48 | } |
| 49 | public function woocommerce_average_order_volume() |
| 50 | { |
| 51 | $gross_sales = $this->wc_gross_sales(); |
| 52 | $orders = $this->wc_orders(); |
| 53 | if ($orders === 0) { |
| 54 | return 0; |
| 55 | } |
| 56 | return $gross_sales / $orders; |
| 57 | } |
| 58 | protected final function set_wc_stats($row) |
| 59 | { |
| 60 | $this->wc_orders = isset($row->wc_orders) ? \floatval($row->wc_orders) : 0; |
| 61 | $this->wc_gross_sales = isset($row->wc_gross_sales) ? \floatval($row->wc_gross_sales) : 0; |
| 62 | $this->wc_refunds = isset($row->wc_refunds) ? \floatval($row->wc_refunds) : 0; |
| 63 | $this->wc_refunded_amount = isset($row->wc_refunded_amount) ? \floatval($row->wc_refunded_amount) : 0; |
| 64 | } |
| 65 | } |
| 66 |