Table.php
1.61 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
<?php
namespace ACA\WC\Service;
use AC\ListScreen;
use AC\Registerable;
use ACA\WC\ListScreen\Product;
use ACP\ListScreen\Post;
class Table implements Registerable
{
public function register(): void
{
add_action('ac/table/list_screen', [$this, 'fix_manual_product_sort'], 12); // After Sorting is applied
add_filter(
'acp/sorting/remember_last_sorting_preference',
[
$this,
'disable_product_sorting_mode_preference',
],
10,
2
);
add_filter('acp/sticky_header/enable', [$this, 'disable_sticky_headers']);
}
public function fix_manual_product_sort(ListScreen $list_screen): void
{
if (
isset($_GET['orderby']) &&
$list_screen instanceof Post &&
$list_screen->get_post_type() === 'product' &&
strpos($_GET['orderby'], 'menu_order') !== false &&
! filter_input(INPUT_GET, 'orderby')
) {
unset($_GET['orderby']);
}
}
public function disable_sticky_headers(bool $enabled): bool
{
if (
'product' === filter_input(INPUT_GET, 'post_type') &&
'menu_order title' === filter_input(INPUT_GET, 'orderby')
) {
return false;
}
return $enabled;
}
public function disable_product_sorting_mode_preference(bool $enabled, ListScreen $list_screen): bool
{
if ($list_screen instanceof Product && 'menu_order title' === filter_input(INPUT_GET, 'orderby')) {
return false;
}
return $enabled;
}
}