1
|
|
|
<?php |
2
|
|
|
namespace lsx_health_plan\classes\integrations\woocommerce; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Contains the downloads functions post type |
6
|
|
|
* |
7
|
|
|
* @package lsx-health-plan |
8
|
|
|
*/ |
9
|
|
|
class Admin { |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Holds class instance |
13
|
|
|
* |
14
|
|
|
* @since 1.0.0 |
15
|
|
|
* |
16
|
|
|
* @var object \lsx_health_plan\classes\integrations\woocommerce\Admin() |
17
|
|
|
*/ |
18
|
|
|
protected static $instance = null; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Constructor |
22
|
|
|
*/ |
23
|
|
|
public function __construct() { |
24
|
|
|
add_action( 'cmb2_admin_init', array( $this, 'products_metaboxes' ), 5 ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Return an instance of this class. |
29
|
|
|
* |
30
|
|
|
* @since 1.0.0 |
31
|
|
|
* |
32
|
|
|
* @return object \lsx_health_plan\classes\integrations\woocommerce\Admin() A single instance of this class. |
33
|
|
|
*/ |
34
|
|
|
public static function get_instance() { |
35
|
|
|
// If the single instance hasn't been set, set it now. |
36
|
|
|
if ( null === self::$instance ) { |
37
|
|
|
self::$instance = new self(); |
38
|
|
|
} |
39
|
|
|
return self::$instance; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Define the product metabox on the plan post type |
44
|
|
|
*/ |
45
|
|
|
public function products_metaboxes() { |
46
|
|
|
$cmb = new_cmb2_box( |
47
|
|
|
array( |
48
|
|
|
'id' => 'plan_product_metabox', |
49
|
|
|
'title' => __( 'Products', 'lsx-health-plan' ), |
50
|
|
|
'object_types' => array( 'plan' ), // Post type. |
51
|
|
|
'context' => 'side', |
52
|
|
|
'priority' => 'low', |
53
|
|
|
'show_names' => true, |
54
|
|
|
) |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
$cmb->add_field( |
58
|
|
|
array( |
59
|
|
|
'name' => __( 'Search your products', 'lsx-health-plan' ), |
60
|
|
|
'desc' => __( 'Connect the product(s) which sell access to this plan.', 'lsx-health-plan' ), |
61
|
|
|
'id' => 'plan_product', |
62
|
|
|
'type' => 'post_search_ajax', |
63
|
|
|
'limit' => 5, // Limit selection to X items only (default 1). |
64
|
|
|
'sortable' => false, // Allow selected items to be sortable (default false). |
65
|
|
|
'query_args' => array( |
66
|
|
|
'post_type' => 'product', |
67
|
|
|
'post_status' => array( 'publish' ), |
68
|
|
|
'posts_per_page' => -1, |
69
|
|
|
), |
70
|
|
|
) |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|