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