Subscriptions.php
2.64 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
80
81
82
83
84
85
86
<?php
namespace ACA\WC\Service;
use AC;
use AC\Asset\Location\Absolute;
use AC\Registerable;
use ACA\WC\Editing;
use ACA\WC\ListScreen;
use ACA\WC\ListScreen\Product;
use ACA\WC\ListScreenFactory;
use ACA\WC\Search;
use ACP;
use Automattic\WooCommerce\Internal\Admin\Orders\PageController;
final class Subscriptions implements Registerable
{
private $location;
public function __construct(Absolute $location)
{
$this->location = $location;
}
public function register(): void
{
add_action('ac/column_groups', [$this, 'register_column_groups']);
add_action('ac/column_types', [$this, 'add_product_columns']);
add_action('ac/column_types', [$this, 'add_user_columns']);
add_action('ac/table/list_screen', [$this, 'register_table_rows']);
ACP\Search\QueryFactory::register('wc_order_subscription', Search\Query\Order::class);
ACP\Search\TableScreenFactory::register(
ListScreen\OrderSubscription::class,
Search\TableScreen\OrderSubscription::class
);
AC\ListScreenFactory\Aggregate::add(
new ListScreenFactory\OrderSubscriptionFactory(
require $this->location->with_suffix('config/columns/orders_subscriptions.php')->get_path(),
wc_get_container()->get(PageController::class)
)
);
}
public function register_table_rows(AC\ListScreen $list_screen)
{
if ( ! $list_screen instanceof ListScreen\OrderSubscription) {
return;
}
$table_rows = new Editing\TableRows\Order(new AC\Request(), $list_screen);
if ($table_rows->is_request()) {
$table_rows->register();
}
}
public function register_column_groups(AC\Groups $groups): void
{
$groups->add('woocommerce_subscriptions', __('WooCommerce Subscriptions', 'codepress-admin-columns'), 15);
}
public function add_product_columns(AC\ListScreen $list_screen): void
{
if ($list_screen instanceof Product) {
$columns = require $this->location->with_suffix('config/columns/subscription/products.php')->get_path();
foreach ($columns as $column) {
$list_screen->register_column_type(new $column());
}
}
}
public function add_user_columns(AC\ListScreen $list_screen): void
{
if ($list_screen instanceof AC\ListScreen\User) {
$columns = require $this->location->with_suffix('config/columns/subscription/users.php')->get_path();
foreach ($columns as $column) {
$list_screen->register_column_type(new $column());
}
}
}
}