-
Notifications
You must be signed in to change notification settings - Fork 0
/
ac-column-assigned_procedures.php
61 lines (47 loc) · 1.41 KB
/
ac-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 AC_Column_Assigned_Products extends AC_Column {
public function __construct() {
// Identifier, pick an unique name. Single word, no spaces. Underscores allowed.
$this->set_type( 'column-assigned-products' );
// Default column label.
$this->set_label( __( 'Assigned products', 'ac-assigned-products' ) );
}
/**
* Returns the display value for the column.
*
* @param int $post_id ID
* @return string Value
*/
public function get_value( $post_id ) {
// get raw value
$products = $this->get_raw_value( $post_id );
$data = [];
if ( ! empty( $products ) ) {
foreach ( $products as $product ) {
$data[] = '<a href="' . esc_url( get_edit_post_link( $product[ 'id' ] ) ) . '">' . $product[ 'title' ] . '</a>';
}
}
return implode( ',<br>', $data );
}
/**
* Get the raw, underlying value for the column
* Not suitable for direct display, use get_value() for that
* This value will be used by 'inline-edit' and get_value().
*
* @param int $post_id ID
* @return mixed Value
*/
public function get_raw_value( $post_id ) {
$products = get_field( 'kg_order_items', $post_id );
$data = [];
if ( ! empty( $products ) ) {
foreach ( $products as $product ) {
$data[] = [
'id' => $product[ 'kg_order_item' ]->ID,
'title' => $product[ 'kg_order_item' ]->post_title,
];
}
}
return $data;
}
}