-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacp-column-assigned_procedures.php
61 lines (48 loc) · 1.39 KB
/
acp-column-assigned_procedures.php
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
<?php
class ACP_Column_Assigned_Products extends AC_Column_Assigned_Products
implements ACP_Column_FilteringInterface {
public function filtering() {
return new ACP_Filtering_Model_Assigned_Products( $this );
}
}
/**
* Filtering class.
*/
class ACP_Filtering_Model_Assigned_Products extends ACP_Filtering_Model {
public function get_filtering_vars( $vars ) {
add_filter( 'posts_where', function ( $where ) {
$where = str_replace( "meta_key = 'kg_order_items_", "meta_key LIKE 'kg_order_items_", $where );
return $where;
} );
$product_id = $this->get_filter_value();
$vars[ 'meta_query' ][] = [
'key' => 'kg_order_items_%_kg_order_item',
'compare' => '=',
'value' => $product_id,
];
return $vars;
}
public function get_filtering_data() {
return [
'order' => 'label',
'empty_option' => false,
'options' => $this->get_products_for_dropdown(),
];
}
private function get_products_for_dropdown() {
$args = [
'posts_per_page' => -1,
'post_type' => 'product',
];
$products_query = new \WP_Query( $args );
$data = [];
if ( $products_query->have_posts() ) {
while ( $products_query->have_posts() ) {
$products_query->the_post();
$data[ $products_query->post->ID ] = $products_query->post->post_title;
}
wp_reset_postdata();
}
return $data;
}
}