CustomerSince.php
1.27 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
<?php
namespace ACA\WC\Column\User;
use AC;
use ACA\WC\Sorting;
use ACP\ConditionalFormat\Formattable;
use ACP\ConditionalFormat\FormattableConfig;
use ACP\ConditionalFormat\Formatter\DateFormatter;
use ACP\Sorting\Sortable;
/**
* @since 3.0
*/
class CustomerSince extends AC\Column implements Sortable, Formattable {
public function __construct() {
$this->set_type( 'column-wc-user-customer_since' )
->set_label( __( 'Customer Since', 'codepress-admin-columns' ) )
->set_group( 'woocommerce' );
}
public function get_raw_value( $customer_id ) {
$orders = wc_get_orders( [
'limit' => 1,
'status' => 'wc-completed',
'customer_id' => $customer_id,
'orderby' => 'date',
'order' => 'ASC',
] );
if ( ! $orders ) {
return false;
}
$order = $orders[0];
$date = $order->get_date_created();
if ( ! $date ) {
return false;
}
return $date->format( 'Y-m-d' );
}
public function conditional_format(): ?FormattableConfig {
return new FormattableConfig( new DateFormatter\FormatFormatter( 'Y-m-d' ) );
}
public function register_settings() {
$this->add_setting( new AC\Settings\Column\Date( $this ) );
}
public function sorting() {
return new Sorting\User\OrderDate\FirstOrder( [ 'wc-completed' ] );
}
}