functions.php
2.44 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
if( ! function_exists('wc_rbp_update_acs_role_based_price') ) {
/**
* Updates Products Role Based Price Array In DB
*
* @param int $post_id Post ID To Update
* @param array $price_array Price List
*
* @return boolean [[Description]]
*/
function wc_rbp_update_acs_role_based_price($post_id, $price_array) {
update_post_meta($post_id, '_acs_role_based_price', $price_array);
return TRUE;
}
}
if( ! function_exists('wc_rbp_get_acs_product_price') ) {
/**
* Gets Product price from DB
* #TODO Integrate Wth product_rbp_price function to make it faster
*/
function wc_rbp_get_acs_product_price($post_id, $supress_filter = FALSE) {
$price = get_post_meta($post_id, '_acs_role_based_price');
if( ! empty($price) ) {
$price = $price[0];
} else if( empty($price) ) {
$price = array();
}
if( ! $supress_filter )
$price = apply_filters('wc_rbp_product_acs_prices', $price);
return $price;
}
}
if( ! function_exists('product_acs_rbp_price') ) {
/**
* Gets product price from DB
*/
function product_acs_rbp_price($post_id) {
$price = wc_rbp_product_variable($post_id, 'wc_rbp_acs', 'wc_rbp_get_acs_product_price');
return $price;
}
}
if( ! function_exists('wc_rbp_acs_price') ) {
/**
* Returns Price Based On Give Value
*
* @role : enter role slug / use all to get all roles values
* @price : use selling_price / regular_price or use all to get all values for the given role
*/
function wc_rbp_acs_price($post_id, $role, $currency, $price = 'regular_price', $args = array()) {
$dbprice = product_acs_rbp_price($post_id);
$return = FALSE;
if( $price == 'all' && $role == 'all' ) {
$return = $dbprice;
} else if( $price == 'all' && $role !== 'all' ) {
if( isset($dbprice[$role]) ) {
$return = $dbprice[$role];
}
} else if( $price == 'currency' && $role !== 'all' ) {
if( isset($dbprice[$role]) ) {
$return = $dbprice[$role][$currency];
}
} else if( isset($dbprice[$role][$currency][$price]) ) {
$return = $dbprice[$role][$currency][$price];
}
$return = apply_filters('wc_rbp_product_acs_price', $return, $role, $price, $post_id, $args);
return $return;
}
}