TotalSales.php
1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace ACA\WC\Column\User;
use AC;
use ACA\WC\ConditionalFormat;
use ACA\WC\Export;
use ACA\WC\Helper;
use ACA\WC\Search;
use ACA\WC\Settings\OrderStatuses;
use ACA\WC\Sorting;
use ACP;
use ACP\ConditionalFormat\FormattableConfig;
/**
* @since 1.3
*/
class TotalSales extends AC\Column implements ACP\Sorting\Sortable, ACP\Export\Exportable, ACP\Search\Searchable, ACP\ConditionalFormat\Formattable {
public function __construct() {
$this->set_type( 'column-wc-user-total-sales' )
->set_label( __( 'Total Sales', 'codepress-admin-columns' ) )
->set_group( 'woocommerce' );
}
public function conditional_format(): ?FormattableConfig {
return new FormattableConfig( new ConditionalFormat\Formatter\User\TotalSalesFormatter() );
}
/**
* @return string[]
*/
private function get_order_statuses() {
$setting = $this->get_setting( OrderStatuses::NAME );
return $setting instanceof OrderStatuses
? $setting->get_value()
: [ 'wc-completed', 'wc-processing' ];
}
public function get_value( $user_id ) {
$values = [];
foreach ( $this->get_raw_value( $user_id ) as $total ) {
if ( $total ) {
$values[] = wc_price( $total );
}
}
if ( ! $values ) {
return $this->get_empty_char();
}
return implode( ' | ', $values );
}
protected function register_settings() {
parent::register_settings();
$this->add_setting( new OrderStatuses( $this, [ 'wc-completed', 'wc-processing' ] ) );
}
public function get_raw_value( $user_id ) {
return ( new Helper\User )->get_totals_for_user( $user_id, $this->get_order_statuses() );
}
public function sorting() {
return new Sorting\User\TotalSales( $this->get_order_statuses() );
}
public function search() {
return new Search\User\TotalSales( $this->get_order_statuses() );
}
public function export() {
return new ACP\Export\Model\StrippedValue( $this );
}
}