Table.php
1.28 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
<?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() {
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 ) {
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( $enabled ) {
return 'product' === filter_input( INPUT_GET, 'post_type' ) && 'menu_order title' === filter_input( INPUT_GET, 'orderby' )
? false
: $enabled;
}
public function disable_product_sorting_mode_preference( $enabled, ListScreen $list_screen ) {
if ( $list_screen instanceof Product && 'menu_order title' === filter_input( INPUT_GET, 'orderby' ) ) {
return false;
}
return $enabled;
}
}