1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Templating and styling functions. |
4
|
|
|
* |
5
|
|
|
* @class WCSATT_STT_Display |
6
|
|
|
* @since 1.0.0 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
class WCSATT_STT_Display extends WCS_ATT_Display { |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Initialize the display. |
13
|
|
|
* |
14
|
|
|
* @access public |
15
|
|
|
* @static |
16
|
|
|
*/ |
17
|
|
|
public static function init() { |
18
|
|
|
// Adds the sign up fee and trial data to the price html on the 'wcsatt_overridden_subscription_prices_product' filter. |
19
|
|
|
add_filter( 'wcsatt_overridden_subscription_prices_product', __CLASS__ . '::add_sub_scheme_data_price_html', 10, 3 ); |
20
|
|
|
|
21
|
|
|
// Adds the extra subscription scheme data to the product object on the 'wcsatt_converted_product_for_scheme_option' filter. |
22
|
|
|
add_filter( 'wcsatt_converted_product_for_scheme_option', __CLASS__ . '::sub_product_scheme_option', 10, 2 ); |
23
|
|
|
|
24
|
|
|
// Filters the price string to include the sign up fee and/or trial to pass per scheme option on the 'wcsatt_single_product_subscription_scheme_price_html' filter. |
25
|
|
|
add_filter( 'wcsatt_single_product_subscription_scheme_price_html', __CLASS__ . '::get_price_string', 10, 2 ); |
26
|
|
|
|
27
|
|
|
// Filters the lowest price string to include the sign up fee on the 'wcsatt_get_single_product_lowest_price_string' filter. |
28
|
|
|
add_filter( 'wcsatt_get_single_product_lowest_price_string', __CLASS__ . '::get_lowest_price_string', 10, 2 ); |
29
|
|
|
|
30
|
|
|
// Filters the lowest price subscription scheme data on the 'wcsatt_get_lowest_price_sub_scheme_data' filter. |
31
|
|
|
add_filter( 'wcsatt_get_lowest_price_sub_scheme_data', __CLASS__ . '::get_lowest_price_sub_scheme_data', 10, 2 ); |
32
|
|
|
|
33
|
|
|
// Adds the sign-up and/or trial data to the subscription scheme prices on the 'wcsatt_subscription_scheme_prices' filter. |
34
|
|
|
add_filter( 'wcsatt_subscription_scheme_prices', __CLASS__ . '::add_subscription_scheme_prices', 10, 2 ); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Adds the additional subscription scheme data for products with attached subscription schemes. |
39
|
|
|
* |
40
|
|
|
* @access public |
41
|
|
|
* @static |
42
|
|
|
* @param object $_product |
43
|
|
|
* @param array $subscription_scheme |
44
|
|
|
* @param WC_Product $product |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
public static function add_sub_scheme_data_price_html( $_product, $subscription_scheme, $product ) { |
48
|
|
|
if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) ) { |
49
|
|
|
$_product->subscription_sign_up_fee = $subscription_scheme[ 'subscription_sign_up_fee' ]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) ) { |
53
|
|
|
$_product->subscription_trial_length = $subscription_scheme[ 'subscription_trial_length' ]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if ( isset( $subscription_scheme[ 'subscription_trial_period' ] ) ) { |
57
|
|
|
$_product->subscription_trial_period = $subscription_scheme[ 'subscription_trial_period' ]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $_product; |
61
|
|
|
} // END add_sub_scheme_data_price_html() |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Adds the extra subscription scheme data to the product object. |
65
|
|
|
* This allows the subscription price to change the initial and |
66
|
|
|
* recurring subscriptions. |
67
|
|
|
* |
68
|
|
|
* @access public |
69
|
|
|
* @static |
70
|
|
|
* @param object $_cloned |
71
|
|
|
* @param array $subscription_scheme |
72
|
|
|
* @return object |
73
|
|
|
*/ |
74
|
|
|
public static function sub_product_scheme_option( $_cloned, $subscription_scheme ) { |
75
|
|
|
if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) && $subscription_scheme[ 'subscription_sign_up_fee' ] > 0 ) { |
76
|
|
|
$_cloned->subscription_sign_up_fee = $subscription_scheme[ 'subscription_sign_up_fee' ]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) && 0 != $subscription_scheme[ 'subscription_trial_length' ] ) { |
80
|
|
|
$_cloned->subscription_trial_length = $subscription_scheme[ 'subscription_trial_length' ]; |
81
|
|
|
$_cloned->subscription_trial_period = $subscription_scheme[ 'subscription_trial_period' ]; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $_cloned; |
85
|
|
|
} // END sub_product_scheme_option() |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Filters the price string to include the sign up fee and/or trial |
89
|
|
|
* to pass per subscription scheme option. |
90
|
|
|
* |
91
|
|
|
* @access public |
92
|
|
|
* @static |
93
|
|
|
* @param array $prices |
94
|
|
|
* @param array $subscription_scheme |
95
|
|
|
* @return array |
96
|
|
|
*/ |
97
|
|
|
public static function get_price_string( $prices, $subscription_scheme ) { |
98
|
|
|
if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) && $subscription_scheme[ 'subscription_sign_up_fee' ] > 0 ) { |
99
|
|
|
$prices[ 'sign_up_fee' ] = $subscription_scheme[ 'subscription_sign_up_fee' ]; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) && 0 != $subscription_scheme[ 'subscription_trial_length' ] ) { |
103
|
|
|
$prices[ 'trial_length' ] = true; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $prices; |
107
|
|
|
} // END get_price_string() |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Filters the price string to include the sign up |
111
|
|
|
* fee on the lowest subscription scheme. |
112
|
|
|
* |
113
|
|
|
* @access public |
114
|
|
|
* @static |
115
|
|
|
* @param array $prices |
116
|
|
|
* @param array $lowest_subscription_scheme |
117
|
|
|
* @return array |
118
|
|
|
*/ |
119
|
|
|
public static function get_lowest_price_string( $prices, $lowest_subscription_scheme ) { |
120
|
|
|
if ( isset( $lowest_subscription_scheme[ 'sign_up_fee' ] ) && $lowest_subscription_scheme[ 'sign_up_fee' ] > 0 ) { |
121
|
|
|
$prices[ 'sign_up_fee' ] = $lowest_subscription_scheme[ 'sign_up_fee' ]; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return $prices; |
125
|
|
|
} // END get_lowest_price_string() |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Adds the sign-up fee to the lowest subscription scheme option. |
129
|
|
|
* |
130
|
|
|
* @access public |
131
|
|
|
* @static |
132
|
|
|
* @param array $data |
133
|
|
|
* @param array $lowest_scheme |
134
|
|
|
* @return array |
135
|
|
|
*/ |
136
|
|
|
public static function get_lowest_price_sub_scheme_data( $data, $lowest_scheme ) { |
137
|
|
|
if ( isset( $lowest_scheme['subscription_sign_up_fee'] ) && $lowest_scheme['subscription_sign_up_fee'] > 0 ) { |
138
|
|
|
$data['sign_up_fee'] = $lowest_scheme['subscription_sign_up_fee']; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
return $data; |
142
|
|
|
} // END get_lowest_price_sub_scheme_data() |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Adds the sign-up and/or trial data to the subscription scheme prices. |
146
|
|
|
* |
147
|
|
|
* @access public |
148
|
|
|
* @static |
149
|
|
|
* @param array $prices |
150
|
|
|
* @param array $subscription_scheme |
151
|
|
|
* @return array |
152
|
|
|
*/ |
153
|
|
|
public static function add_subscription_scheme_prices( $prices, $subscription_scheme ) { |
154
|
|
|
if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) ) { |
155
|
|
|
$prices[ 'sign_up_fee' ] = $subscription_scheme[ 'subscription_sign_up_fee' ]; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) ) { |
159
|
|
|
$prices[ 'trial_length' ] = $subscription_scheme[ 'subscription_trial_length' ]; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
if ( isset( $subscription_scheme[ 'subscription_trial_period' ] ) ) { |
163
|
|
|
$prices[ 'trial_period' ] = $subscription_scheme[ 'subscription_trial_period' ]; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
return $prices; |
167
|
|
|
} // END add_subscription_scheme_prices() |
168
|
|
|
|
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
WCSATT_STT_Display::init(); |
172
|
|
|
|