@@ -15,30 +15,30 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class WPInv_Discount extends GetPaid_Data { |
17 | 17 | |
18 | - /** |
|
19 | - * Which data store to load. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
18 | + /** |
|
19 | + * Which data store to load. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | 23 | protected $data_store_name = 'discount'; |
24 | 24 | |
25 | 25 | /** |
26 | - * This is the name of this object type. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $object_type = 'discount'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Discount Data array. This is the core item data exposed in APIs. |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $data = array( |
|
39 | - 'status' => 'draft', |
|
40 | - 'version' => '', |
|
41 | - 'date_created' => null, |
|
26 | + * This is the name of this object type. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $object_type = 'discount'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Discount Data array. This is the core item data exposed in APIs. |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array( |
|
39 | + 'status' => 'draft', |
|
40 | + 'version' => '', |
|
41 | + 'date_created' => null, |
|
42 | 42 | 'date_modified' => null, |
43 | 43 | 'name' => 'no-name', |
44 | 44 | 'description' => '', |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | 'start' => null, |
50 | 50 | 'items' => array(), |
51 | 51 | 'excluded_items' => array(), |
52 | - 'required_items' => array(), |
|
52 | + 'required_items' => array(), |
|
53 | 53 | 'uses' => 0, |
54 | 54 | 'max_uses' => null, |
55 | 55 | 'is_recurring' => null, |
@@ -59,147 +59,147 @@ discard block |
||
59 | 59 | 'amount' => null, |
60 | 60 | ); |
61 | 61 | |
62 | - /** |
|
63 | - * Stores meta in cache for future reads. |
|
64 | - * |
|
65 | - * A group must be set to to enable caching. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
69 | - protected $cache_group = 'getpaid_discounts'; |
|
62 | + /** |
|
63 | + * Stores meta in cache for future reads. |
|
64 | + * |
|
65 | + * A group must be set to to enable caching. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | + protected $cache_group = 'getpaid_discounts'; |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Stores a reference to the original WP_Post object |
73 | 73 | * |
74 | 74 | * @var WP_Post |
75 | 75 | */ |
76 | - protected $post = null; |
|
77 | - |
|
78 | - /** |
|
79 | - * Get the discount if ID is passed, otherwise the discount is new and empty. |
|
80 | - * |
|
81 | - * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code. |
|
82 | - */ |
|
83 | - public function __construct( $discount = 0 ) { |
|
84 | - parent::__construct( $discount ); |
|
85 | - |
|
86 | - if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) { |
|
87 | - $this->set_id( $discount ); |
|
88 | - } elseif ( $discount instanceof self ) { |
|
89 | - $this->set_id( $discount->get_id() ); |
|
90 | - } elseif ( ! empty( $discount->ID ) ) { |
|
91 | - $this->set_id( $discount->ID ); |
|
92 | - } elseif ( is_array( $discount ) ) { |
|
93 | - $this->set_props( $discount ); |
|
94 | - |
|
95 | - if ( isset( $discount['ID'] ) ) { |
|
96 | - $this->set_id( $discount['ID'] ); |
|
97 | - } |
|
76 | + protected $post = null; |
|
77 | + |
|
78 | + /** |
|
79 | + * Get the discount if ID is passed, otherwise the discount is new and empty. |
|
80 | + * |
|
81 | + * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code. |
|
82 | + */ |
|
83 | + public function __construct( $discount = 0 ) { |
|
84 | + parent::__construct( $discount ); |
|
85 | + |
|
86 | + if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) { |
|
87 | + $this->set_id( $discount ); |
|
88 | + } elseif ( $discount instanceof self ) { |
|
89 | + $this->set_id( $discount->get_id() ); |
|
90 | + } elseif ( ! empty( $discount->ID ) ) { |
|
91 | + $this->set_id( $discount->ID ); |
|
92 | + } elseif ( is_array( $discount ) ) { |
|
93 | + $this->set_props( $discount ); |
|
94 | + |
|
95 | + if ( isset( $discount['ID'] ) ) { |
|
96 | + $this->set_id( $discount['ID'] ); |
|
97 | + } |
|
98 | 98 | } elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) { |
99 | - $this->set_id( $discount ); |
|
100 | - } else { |
|
101 | - $this->set_object_read( true ); |
|
102 | - } |
|
99 | + $this->set_id( $discount ); |
|
100 | + } else { |
|
101 | + $this->set_object_read( true ); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | // Load the datastore. |
105 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
105 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
106 | 106 | |
107 | - if ( $this->get_id() > 0 ) { |
|
107 | + if ( $this->get_id() > 0 ) { |
|
108 | 108 | $this->post = get_post( $this->get_id() ); |
109 | 109 | $this->ID = $this->get_id(); |
110 | - $this->data_store->read( $this ); |
|
110 | + $this->data_store->read( $this ); |
|
111 | 111 | } |
112 | 112 | |
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Fetch a discount from the db/cache |
|
117 | - * |
|
118 | - * |
|
119 | - * @static |
|
120 | - * @param string $field The field to query against: 'ID', 'discount_code' |
|
121 | - * @param string|int $value The field value |
|
122 | - * @deprecated |
|
123 | - * @since 1.0.15 |
|
124 | - * @return array|bool array of discount details on success. False otherwise. |
|
125 | - */ |
|
126 | - public static function get_data_by( $field, $value ) { |
|
127 | - |
|
128 | - if ( 'id' == strtolower( $field ) ) { |
|
129 | - // Make sure the value is numeric to avoid casting objects, for example, |
|
130 | - // to int 1. |
|
131 | - if ( ! is_numeric( $value ) ) { |
|
132 | - return false; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Fetch a discount from the db/cache |
|
117 | + * |
|
118 | + * |
|
119 | + * @static |
|
120 | + * @param string $field The field to query against: 'ID', 'discount_code' |
|
121 | + * @param string|int $value The field value |
|
122 | + * @deprecated |
|
123 | + * @since 1.0.15 |
|
124 | + * @return array|bool array of discount details on success. False otherwise. |
|
125 | + */ |
|
126 | + public static function get_data_by( $field, $value ) { |
|
127 | + |
|
128 | + if ( 'id' == strtolower( $field ) ) { |
|
129 | + // Make sure the value is numeric to avoid casting objects, for example, |
|
130 | + // to int 1. |
|
131 | + if ( ! is_numeric( $value ) ) { |
|
132 | + return false; |
|
133 | 133 | } |
134 | - $value = intval( $value ); |
|
135 | - if ( $value < 1 ) { |
|
136 | - return false; |
|
134 | + $value = intval( $value ); |
|
135 | + if ( $value < 1 ) { |
|
136 | + return false; |
|
137 | 137 | } |
138 | - } |
|
139 | - |
|
140 | - if ( ! $value || ! is_string( $field ) ) { |
|
141 | - return false; |
|
142 | - } |
|
143 | - |
|
144 | - $field = trim( $field ); |
|
145 | - |
|
146 | - // prepare query args |
|
147 | - switch ( strtolower( $field ) ) { |
|
148 | - case 'id': |
|
149 | - $discount_id = $value; |
|
150 | - $args = array( 'include' => array( $value ) ); |
|
151 | - break; |
|
152 | - case 'discount_code': |
|
153 | - case 'code': |
|
154 | - $value = trim( $value ); |
|
155 | - $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' ); |
|
156 | - $args = array( |
|
157 | - 'meta_key' => '_wpi_discount_code', |
|
158 | - 'meta_value' => $value, |
|
159 | - ); |
|
160 | - break; |
|
161 | - case 'name': |
|
162 | - $discount_id = 0; |
|
163 | - $args = array( 'name' => trim( $value ) ); |
|
164 | - break; |
|
165 | - default: |
|
166 | - $args = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value ); |
|
167 | - if ( ! is_array( $args ) ) { |
|
168 | - return apply_filters( "wpinv_discount_get_data_by_$field", false, $value ); |
|
169 | - } |
|
138 | + } |
|
139 | + |
|
140 | + if ( ! $value || ! is_string( $field ) ) { |
|
141 | + return false; |
|
142 | + } |
|
143 | + |
|
144 | + $field = trim( $field ); |
|
145 | + |
|
146 | + // prepare query args |
|
147 | + switch ( strtolower( $field ) ) { |
|
148 | + case 'id': |
|
149 | + $discount_id = $value; |
|
150 | + $args = array( 'include' => array( $value ) ); |
|
151 | + break; |
|
152 | + case 'discount_code': |
|
153 | + case 'code': |
|
154 | + $value = trim( $value ); |
|
155 | + $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' ); |
|
156 | + $args = array( |
|
157 | + 'meta_key' => '_wpi_discount_code', |
|
158 | + 'meta_value' => $value, |
|
159 | + ); |
|
160 | + break; |
|
161 | + case 'name': |
|
162 | + $discount_id = 0; |
|
163 | + $args = array( 'name' => trim( $value ) ); |
|
164 | + break; |
|
165 | + default: |
|
166 | + $args = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value ); |
|
167 | + if ( ! is_array( $args ) ) { |
|
168 | + return apply_filters( "wpinv_discount_get_data_by_$field", false, $value ); |
|
169 | + } |
|
170 | 170 | } |
171 | 171 | |
172 | - // Check if there is a cached value. |
|
173 | - if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) { |
|
174 | - return $discount; |
|
175 | - } |
|
172 | + // Check if there is a cached value. |
|
173 | + if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) { |
|
174 | + return $discount; |
|
175 | + } |
|
176 | 176 | |
177 | - $args = array_merge( |
|
178 | - $args, |
|
179 | - array( |
|
180 | - 'post_type' => 'wpi_discount', |
|
181 | - 'posts_per_page' => 1, |
|
182 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
183 | - ) |
|
184 | - ); |
|
177 | + $args = array_merge( |
|
178 | + $args, |
|
179 | + array( |
|
180 | + 'post_type' => 'wpi_discount', |
|
181 | + 'posts_per_page' => 1, |
|
182 | + 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
183 | + ) |
|
184 | + ); |
|
185 | 185 | |
186 | - $discount = get_posts( $args ); |
|
186 | + $discount = get_posts( $args ); |
|
187 | 187 | |
188 | - if ( empty( $discount ) ) { |
|
189 | - return false; |
|
190 | - } |
|
188 | + if ( empty( $discount ) ) { |
|
189 | + return false; |
|
190 | + } |
|
191 | 191 | |
192 | - $discount = $discount[0]; |
|
192 | + $discount = $discount[0]; |
|
193 | 193 | |
194 | - // Prepare the return data. |
|
195 | - $return = array( |
|
194 | + // Prepare the return data. |
|
195 | + $return = array( |
|
196 | 196 | 'ID' => $discount->ID, |
197 | 197 | 'code' => get_post_meta( $discount->ID, '_wpi_discount_code', true ), |
198 | 198 | 'amount' => get_post_meta( $discount->ID, '_wpi_discount_amount', true ), |
199 | 199 | 'date_created' => $discount->post_date, |
200 | - 'date_modified' => $discount->post_modified, |
|
201 | - 'status' => $discount->post_status, |
|
202 | - 'start' => get_post_meta( $discount->ID, '_wpi_discount_start', true ), |
|
200 | + 'date_modified' => $discount->post_modified, |
|
201 | + 'status' => $discount->post_status, |
|
202 | + 'start' => get_post_meta( $discount->ID, '_wpi_discount_start', true ), |
|
203 | 203 | 'expiration' => get_post_meta( $discount->ID, '_wpi_discount_expiration', true ), |
204 | 204 | 'type' => get_post_meta( $discount->ID, '_wpi_discount_type', true ), |
205 | 205 | 'description' => $discount->post_excerpt, |
@@ -207,84 +207,84 @@ discard block |
||
207 | 207 | 'is_single_use' => get_post_meta( $discount->ID, '_wpi_discount_is_single_use', true ), |
208 | 208 | 'items' => get_post_meta( $discount->ID, '_wpi_discount_items', true ), |
209 | 209 | 'excluded_items' => get_post_meta( $discount->ID, '_wpi_discount_excluded_items', true ), |
210 | - 'required_items' => get_post_meta( $discount->ID, '_wpi_discount_required_items', true ), |
|
210 | + 'required_items' => get_post_meta( $discount->ID, '_wpi_discount_required_items', true ), |
|
211 | 211 | 'max_uses' => get_post_meta( $discount->ID, '_wpi_discount_max_uses', true ), |
212 | 212 | 'is_recurring' => get_post_meta( $discount->ID, '_wpi_discount_is_recurring', true ), |
213 | 213 | 'min_total' => get_post_meta( $discount->ID, '_wpi_discount_min_total', true ), |
214 | 214 | 'max_total' => get_post_meta( $discount->ID, '_wpi_discount_max_total', true ), |
215 | 215 | ); |
216 | 216 | |
217 | - $return = apply_filters( 'wpinv_discount_properties', $return ); |
|
218 | - |
|
219 | - // Update the cache with our data |
|
220 | - wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' ); |
|
221 | - wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' ); |
|
222 | - |
|
223 | - return $return; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Given a discount code, it returns a discount id. |
|
228 | - * |
|
229 | - * |
|
230 | - * @static |
|
231 | - * @param string $discount_code |
|
232 | - * @since 1.0.15 |
|
233 | - * @return int |
|
234 | - */ |
|
235 | - public static function get_discount_id_by_code( $discount_code ) { |
|
236 | - |
|
237 | - // Trim the code. |
|
238 | - $discount_code = trim( $discount_code ); |
|
239 | - |
|
240 | - // Ensure a value has been passed. |
|
241 | - if ( empty( $discount_code ) ) { |
|
242 | - return 0; |
|
243 | - } |
|
244 | - |
|
245 | - // Maybe retrieve from the cache. |
|
246 | - $discount_id = wp_cache_get( $discount_code, 'getpaid_discount_codes' ); |
|
247 | - if ( ! empty( $discount_id ) ) { |
|
248 | - return $discount_id; |
|
249 | - } |
|
250 | - |
|
251 | - // Fetch the first discount codes. |
|
252 | - $discounts = get_posts( |
|
253 | - array( |
|
254 | - 'meta_key' => '_wpi_discount_code', |
|
255 | - 'meta_value' => $discount_code, |
|
256 | - 'post_type' => 'wpi_discount', |
|
257 | - 'posts_per_page' => 1, |
|
258 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
259 | - 'fields' => 'ids', |
|
260 | - ) |
|
261 | - ); |
|
262 | - |
|
263 | - if ( empty( $discounts ) ) { |
|
264 | - return 0; |
|
265 | - } |
|
266 | - |
|
267 | - $discount_id = $discounts[0]; |
|
268 | - |
|
269 | - // Update the cache with our data |
|
270 | - wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' ); |
|
271 | - |
|
272 | - return $discount_id; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Magic method for checking the existence of a certain custom field. |
|
277 | - * |
|
278 | - * @since 1.0.15 |
|
279 | - * @access public |
|
280 | - * |
|
281 | - * @return bool Whether the given discount field is set. |
|
282 | - */ |
|
283 | - public function __isset( $key ) { |
|
284 | - return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" ); |
|
285 | - } |
|
286 | - |
|
287 | - /* |
|
217 | + $return = apply_filters( 'wpinv_discount_properties', $return ); |
|
218 | + |
|
219 | + // Update the cache with our data |
|
220 | + wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' ); |
|
221 | + wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' ); |
|
222 | + |
|
223 | + return $return; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Given a discount code, it returns a discount id. |
|
228 | + * |
|
229 | + * |
|
230 | + * @static |
|
231 | + * @param string $discount_code |
|
232 | + * @since 1.0.15 |
|
233 | + * @return int |
|
234 | + */ |
|
235 | + public static function get_discount_id_by_code( $discount_code ) { |
|
236 | + |
|
237 | + // Trim the code. |
|
238 | + $discount_code = trim( $discount_code ); |
|
239 | + |
|
240 | + // Ensure a value has been passed. |
|
241 | + if ( empty( $discount_code ) ) { |
|
242 | + return 0; |
|
243 | + } |
|
244 | + |
|
245 | + // Maybe retrieve from the cache. |
|
246 | + $discount_id = wp_cache_get( $discount_code, 'getpaid_discount_codes' ); |
|
247 | + if ( ! empty( $discount_id ) ) { |
|
248 | + return $discount_id; |
|
249 | + } |
|
250 | + |
|
251 | + // Fetch the first discount codes. |
|
252 | + $discounts = get_posts( |
|
253 | + array( |
|
254 | + 'meta_key' => '_wpi_discount_code', |
|
255 | + 'meta_value' => $discount_code, |
|
256 | + 'post_type' => 'wpi_discount', |
|
257 | + 'posts_per_page' => 1, |
|
258 | + 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
259 | + 'fields' => 'ids', |
|
260 | + ) |
|
261 | + ); |
|
262 | + |
|
263 | + if ( empty( $discounts ) ) { |
|
264 | + return 0; |
|
265 | + } |
|
266 | + |
|
267 | + $discount_id = $discounts[0]; |
|
268 | + |
|
269 | + // Update the cache with our data |
|
270 | + wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' ); |
|
271 | + |
|
272 | + return $discount_id; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Magic method for checking the existence of a certain custom field. |
|
277 | + * |
|
278 | + * @since 1.0.15 |
|
279 | + * @access public |
|
280 | + * |
|
281 | + * @return bool Whether the given discount field is set. |
|
282 | + */ |
|
283 | + public function __isset( $key ) { |
|
284 | + return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" ); |
|
285 | + } |
|
286 | + |
|
287 | + /* |
|
288 | 288 | |-------------------------------------------------------------------------- |
289 | 289 | | CRUD methods |
290 | 290 | |-------------------------------------------------------------------------- |
@@ -299,441 +299,441 @@ discard block |
||
299 | 299 | |-------------------------------------------------------------------------- |
300 | 300 | */ |
301 | 301 | |
302 | - /** |
|
303 | - * Get discount status. |
|
304 | - * |
|
305 | - * @since 1.0.19 |
|
306 | - * @param string $context View or edit context. |
|
307 | - * @return string |
|
308 | - */ |
|
309 | - public function get_status( $context = 'view' ) { |
|
310 | - return $this->get_prop( 'status', $context ); |
|
302 | + /** |
|
303 | + * Get discount status. |
|
304 | + * |
|
305 | + * @since 1.0.19 |
|
306 | + * @param string $context View or edit context. |
|
307 | + * @return string |
|
308 | + */ |
|
309 | + public function get_status( $context = 'view' ) { |
|
310 | + return $this->get_prop( 'status', $context ); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
314 | - * Get plugin version when the discount was created. |
|
315 | - * |
|
316 | - * @since 1.0.19 |
|
317 | - * @param string $context View or edit context. |
|
318 | - * @return string |
|
319 | - */ |
|
320 | - public function get_version( $context = 'view' ) { |
|
321 | - return $this->get_prop( 'version', $context ); |
|
314 | + * Get plugin version when the discount was created. |
|
315 | + * |
|
316 | + * @since 1.0.19 |
|
317 | + * @param string $context View or edit context. |
|
318 | + * @return string |
|
319 | + */ |
|
320 | + public function get_version( $context = 'view' ) { |
|
321 | + return $this->get_prop( 'version', $context ); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
325 | - * Get date when the discount was created. |
|
326 | - * |
|
327 | - * @since 1.0.19 |
|
328 | - * @param string $context View or edit context. |
|
329 | - * @return string |
|
330 | - */ |
|
331 | - public function get_date_created( $context = 'view' ) { |
|
332 | - return $this->get_prop( 'date_created', $context ); |
|
325 | + * Get date when the discount was created. |
|
326 | + * |
|
327 | + * @since 1.0.19 |
|
328 | + * @param string $context View or edit context. |
|
329 | + * @return string |
|
330 | + */ |
|
331 | + public function get_date_created( $context = 'view' ) { |
|
332 | + return $this->get_prop( 'date_created', $context ); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
336 | - * Get GMT date when the discount was created. |
|
337 | - * |
|
338 | - * @since 1.0.19 |
|
339 | - * @param string $context View or edit context. |
|
340 | - * @return string |
|
341 | - */ |
|
342 | - public function get_date_created_gmt( $context = 'view' ) { |
|
336 | + * Get GMT date when the discount was created. |
|
337 | + * |
|
338 | + * @since 1.0.19 |
|
339 | + * @param string $context View or edit context. |
|
340 | + * @return string |
|
341 | + */ |
|
342 | + public function get_date_created_gmt( $context = 'view' ) { |
|
343 | 343 | $date = $this->get_date_created( $context ); |
344 | 344 | |
345 | 345 | if ( $date ) { |
346 | 346 | $date = get_gmt_from_date( $date ); |
347 | 347 | } |
348 | - return $date; |
|
348 | + return $date; |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
352 | - * Get date when the discount was last modified. |
|
353 | - * |
|
354 | - * @since 1.0.19 |
|
355 | - * @param string $context View or edit context. |
|
356 | - * @return string |
|
357 | - */ |
|
358 | - public function get_date_modified( $context = 'view' ) { |
|
359 | - return $this->get_prop( 'date_modified', $context ); |
|
352 | + * Get date when the discount was last modified. |
|
353 | + * |
|
354 | + * @since 1.0.19 |
|
355 | + * @param string $context View or edit context. |
|
356 | + * @return string |
|
357 | + */ |
|
358 | + public function get_date_modified( $context = 'view' ) { |
|
359 | + return $this->get_prop( 'date_modified', $context ); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | /** |
363 | - * Get GMT date when the discount was last modified. |
|
364 | - * |
|
365 | - * @since 1.0.19 |
|
366 | - * @param string $context View or edit context. |
|
367 | - * @return string |
|
368 | - */ |
|
369 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
363 | + * Get GMT date when the discount was last modified. |
|
364 | + * |
|
365 | + * @since 1.0.19 |
|
366 | + * @param string $context View or edit context. |
|
367 | + * @return string |
|
368 | + */ |
|
369 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
370 | 370 | $date = $this->get_date_modified( $context ); |
371 | 371 | |
372 | 372 | if ( $date ) { |
373 | 373 | $date = get_gmt_from_date( $date ); |
374 | 374 | } |
375 | - return $date; |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Get the discount name. |
|
380 | - * |
|
381 | - * @since 1.0.19 |
|
382 | - * @param string $context View or edit context. |
|
383 | - * @return string |
|
384 | - */ |
|
385 | - public function get_name( $context = 'view' ) { |
|
386 | - return $this->get_prop( 'name', $context ); |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Alias of self::get_name(). |
|
391 | - * |
|
392 | - * @since 1.0.19 |
|
393 | - * @param string $context View or edit context. |
|
394 | - * @return string |
|
395 | - */ |
|
396 | - public function get_title( $context = 'view' ) { |
|
397 | - return $this->get_name( $context ); |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * Get the discount description. |
|
402 | - * |
|
403 | - * @since 1.0.19 |
|
404 | - * @param string $context View or edit context. |
|
405 | - * @return string |
|
406 | - */ |
|
407 | - public function get_description( $context = 'view' ) { |
|
408 | - return $this->get_prop( 'description', $context ); |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * Alias of self::get_description(). |
|
413 | - * |
|
414 | - * @since 1.0.19 |
|
415 | - * @param string $context View or edit context. |
|
416 | - * @return string |
|
417 | - */ |
|
418 | - public function get_excerpt( $context = 'view' ) { |
|
419 | - return $this->get_description( $context ); |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Alias of self::get_description(). |
|
424 | - * |
|
425 | - * @since 1.0.19 |
|
426 | - * @param string $context View or edit context. |
|
427 | - * @return string |
|
428 | - */ |
|
429 | - public function get_summary( $context = 'view' ) { |
|
430 | - return $this->get_description( $context ); |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * Get the owner of the discount. |
|
435 | - * |
|
436 | - * @since 1.0.19 |
|
437 | - * @param string $context View or edit context. |
|
438 | - * @return string |
|
439 | - */ |
|
440 | - public function get_author( $context = 'view' ) { |
|
441 | - return (int) $this->get_prop( 'author', $context ); |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * Get the discount code. |
|
446 | - * |
|
447 | - * @since 1.0.19 |
|
448 | - * @param string $context View or edit context. |
|
449 | - * @return string |
|
450 | - */ |
|
451 | - public function get_code( $context = 'view' ) { |
|
452 | - return $this->get_prop( 'code', $context ); |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Alias for self::get_code(). |
|
457 | - * |
|
458 | - * @since 1.0.19 |
|
459 | - * @param string $context View or edit context. |
|
460 | - * @return string |
|
461 | - */ |
|
462 | - public function get_coupon_code( $context = 'view' ) { |
|
463 | - return $this->get_code( $context ); |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * Alias for self::get_code(). |
|
468 | - * |
|
469 | - * @since 1.0.19 |
|
470 | - * @param string $context View or edit context. |
|
471 | - * @return string |
|
472 | - */ |
|
473 | - public function get_discount_code( $context = 'view' ) { |
|
474 | - return $this->get_code( $context ); |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * Get the discount's amount. |
|
479 | - * |
|
480 | - * @since 1.0.19 |
|
481 | - * @param string $context View or edit context. |
|
482 | - * @return float |
|
483 | - */ |
|
484 | - public function get_amount( $context = 'view' ) { |
|
485 | - return $context == 'view' ? floatval( $this->get_prop( 'amount', $context ) ) : $this->get_prop( 'amount', $context ); |
|
486 | - } |
|
487 | - |
|
488 | - /** |
|
489 | - * Get the discount's formated amount/rate. |
|
490 | - * |
|
491 | - * @since 1.0.19 |
|
492 | - * @return string |
|
493 | - */ |
|
494 | - public function get_formatted_amount() { |
|
495 | - |
|
496 | - if ( $this->is_type( 'flat' ) ) { |
|
497 | - $rate = wpinv_price( $this->get_amount() ); |
|
498 | - } else { |
|
499 | - $rate = $this->get_amount() . '%'; |
|
500 | - } |
|
501 | - |
|
502 | - return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() ); |
|
503 | - } |
|
504 | - |
|
505 | - /** |
|
506 | - * Get the discount's start date. |
|
507 | - * |
|
508 | - * @since 1.0.19 |
|
509 | - * @param string $context View or edit context. |
|
510 | - * @return string |
|
511 | - */ |
|
512 | - public function get_start( $context = 'view' ) { |
|
513 | - return $this->get_prop( 'start', $context ); |
|
514 | - } |
|
515 | - |
|
516 | - /** |
|
517 | - * Alias for self::get_start(). |
|
518 | - * |
|
519 | - * @since 1.0.19 |
|
520 | - * @param string $context View or edit context. |
|
521 | - * @return string |
|
522 | - */ |
|
523 | - public function get_start_date( $context = 'view' ) { |
|
524 | - return $this->get_start( $context ); |
|
525 | - } |
|
526 | - |
|
527 | - /** |
|
528 | - * Get the discount's expiration date. |
|
529 | - * |
|
530 | - * @since 1.0.19 |
|
531 | - * @param string $context View or edit context. |
|
532 | - * @return string |
|
533 | - */ |
|
534 | - public function get_expiration( $context = 'view' ) { |
|
535 | - return $this->get_prop( 'expiration', $context ); |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Alias for self::get_expiration(). |
|
540 | - * |
|
541 | - * @since 1.0.19 |
|
542 | - * @param string $context View or edit context. |
|
543 | - * @return string |
|
544 | - */ |
|
545 | - public function get_expiration_date( $context = 'view' ) { |
|
546 | - return $this->get_expiration( $context ); |
|
547 | - } |
|
548 | - |
|
549 | - /** |
|
550 | - * Alias for self::get_expiration(). |
|
551 | - * |
|
552 | - * @since 1.0.19 |
|
553 | - * @param string $context View or edit context. |
|
554 | - * @return string |
|
555 | - */ |
|
556 | - public function get_end_date( $context = 'view' ) { |
|
557 | - return $this->get_expiration( $context ); |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Get the discount's type. |
|
562 | - * |
|
563 | - * @since 1.0.19 |
|
564 | - * @param string $context View or edit context. |
|
565 | - * @return string |
|
566 | - */ |
|
567 | - public function get_type( $context = 'view' ) { |
|
568 | - return $this->get_prop( 'type', $context ); |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Get the number of times a discount has been used. |
|
573 | - * |
|
574 | - * @since 1.0.19 |
|
575 | - * @param string $context View or edit context. |
|
576 | - * @return int |
|
577 | - */ |
|
578 | - public function get_uses( $context = 'view' ) { |
|
579 | - return (int) $this->get_prop( 'uses', $context ); |
|
580 | - } |
|
581 | - |
|
582 | - /** |
|
583 | - * Get the discount's usage, i.e uses / max uses. |
|
584 | - * |
|
585 | - * @since 1.0.19 |
|
586 | - * @return string |
|
587 | - */ |
|
588 | - public function get_usage() { |
|
589 | - |
|
590 | - if ( ! $this->has_limit() ) { |
|
591 | - return $this->get_uses() . ' / ' . ' ∞'; |
|
592 | - } |
|
593 | - |
|
594 | - return $this->get_uses() . ' / ' . (int) $this->get_max_uses(); |
|
595 | - |
|
596 | - } |
|
597 | - |
|
598 | - /** |
|
599 | - * Get the maximum number of time a discount can be used. |
|
600 | - * |
|
601 | - * @since 1.0.19 |
|
602 | - * @param string $context View or edit context. |
|
603 | - * @return int |
|
604 | - */ |
|
605 | - public function get_max_uses( $context = 'view' ) { |
|
606 | - $max_uses = $this->get_prop( 'max_uses', $context ); |
|
607 | - return empty( $max_uses ) ? null : $max_uses; |
|
608 | - } |
|
609 | - |
|
610 | - /** |
|
611 | - * Checks if this is a single use discount or not. |
|
612 | - * |
|
613 | - * @since 1.0.19 |
|
614 | - * @param string $context View or edit context. |
|
615 | - * @return bool |
|
616 | - */ |
|
617 | - public function get_is_single_use( $context = 'view' ) { |
|
618 | - return $this->get_prop( 'is_single_use', $context ); |
|
619 | - } |
|
620 | - |
|
621 | - /** |
|
622 | - * Get the items that can be used with this discount. |
|
623 | - * |
|
624 | - * @since 1.0.19 |
|
625 | - * @param string $context View or edit context. |
|
626 | - * @return array |
|
627 | - */ |
|
628 | - public function get_items( $context = 'view' ) { |
|
629 | - return array_filter( wp_parse_id_list( $this->get_prop( 'items', $context ) ) ); |
|
630 | - } |
|
631 | - |
|
632 | - /** |
|
633 | - * Alias for self::get_items(). |
|
634 | - * |
|
635 | - * @since 1.0.19 |
|
636 | - * @param string $context View or edit context. |
|
637 | - * @return array |
|
638 | - */ |
|
639 | - public function get_allowed_items( $context = 'view' ) { |
|
640 | - return $this->get_items( $context ); |
|
641 | - } |
|
642 | - |
|
643 | - /** |
|
644 | - * Get the items that are not allowed to use this discount. |
|
645 | - * |
|
646 | - * @since 1.0.19 |
|
647 | - * @param string $context View or edit context. |
|
648 | - * @return array |
|
649 | - */ |
|
650 | - public function get_excluded_items( $context = 'view' ) { |
|
651 | - return array_filter( wp_parse_id_list( $this->get_prop( 'excluded_items', $context ) ) ); |
|
652 | - } |
|
653 | - |
|
654 | - /** |
|
655 | - * Get the items that are required to be in the cart before using this discount. |
|
656 | - * |
|
657 | - * @since 1.0.19 |
|
658 | - * @param string $context View or edit context. |
|
659 | - * @return array |
|
660 | - */ |
|
661 | - public function get_required_items( $context = 'view' ) { |
|
662 | - return array_filter( wp_parse_id_list( $this->get_prop( 'required_items', $context ) ) ); |
|
663 | - } |
|
664 | - |
|
665 | - /** |
|
666 | - * Checks if this is a recurring discount or not. |
|
667 | - * |
|
668 | - * @since 1.0.19 |
|
669 | - * @param string $context View or edit context. |
|
670 | - * @return int|string|bool |
|
671 | - */ |
|
672 | - public function get_is_recurring( $context = 'view' ) { |
|
673 | - return $this->get_prop( 'is_recurring', $context ); |
|
674 | - } |
|
675 | - |
|
676 | - /** |
|
677 | - * Get's the minimum total amount allowed for this discount. |
|
678 | - * |
|
679 | - * @since 1.0.19 |
|
680 | - * @param string $context View or edit context. |
|
681 | - * @return float |
|
682 | - */ |
|
683 | - public function get_min_total( $context = 'view' ) { |
|
684 | - $minimum = $this->get_prop( 'min_total', $context ); |
|
685 | - return empty( $minimum ) ? null : $minimum; |
|
686 | - } |
|
687 | - |
|
688 | - /** |
|
689 | - * Alias for self::get_min_total(). |
|
690 | - * |
|
691 | - * @since 1.0.19 |
|
692 | - * @param string $context View or edit context. |
|
693 | - * @return float |
|
694 | - */ |
|
695 | - public function get_minimum_total( $context = 'view' ) { |
|
696 | - return $this->get_min_total( $context ); |
|
697 | - } |
|
698 | - |
|
699 | - /** |
|
700 | - * Get's the maximum total amount allowed for this discount. |
|
701 | - * |
|
702 | - * @since 1.0.19 |
|
703 | - * @param string $context View or edit context. |
|
704 | - * @return float |
|
705 | - */ |
|
706 | - public function get_max_total( $context = 'view' ) { |
|
707 | - $maximum = $this->get_prop( 'max_total', $context ); |
|
708 | - return empty( $maximum ) ? null : $maximum; |
|
709 | - } |
|
710 | - |
|
711 | - /** |
|
712 | - * Alias for self::get_max_total(). |
|
713 | - * |
|
714 | - * @since 1.0.19 |
|
715 | - * @param string $context View or edit context. |
|
716 | - * @return float |
|
717 | - */ |
|
718 | - public function get_maximum_total( $context = 'view' ) { |
|
719 | - return $this->get_max_total( $context ); |
|
720 | - } |
|
721 | - |
|
722 | - /** |
|
723 | - * Magic method for accessing discount properties. |
|
724 | - * |
|
725 | - * @since 1.0.15 |
|
726 | - * @access public |
|
727 | - * |
|
728 | - * @param string $key Discount data to retrieve |
|
729 | - * @param string $context View or edit context. |
|
730 | - * @return mixed Value of the given discount property (if set). |
|
731 | - */ |
|
732 | - public function get( $key, $context = 'view' ) { |
|
375 | + return $date; |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Get the discount name. |
|
380 | + * |
|
381 | + * @since 1.0.19 |
|
382 | + * @param string $context View or edit context. |
|
383 | + * @return string |
|
384 | + */ |
|
385 | + public function get_name( $context = 'view' ) { |
|
386 | + return $this->get_prop( 'name', $context ); |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Alias of self::get_name(). |
|
391 | + * |
|
392 | + * @since 1.0.19 |
|
393 | + * @param string $context View or edit context. |
|
394 | + * @return string |
|
395 | + */ |
|
396 | + public function get_title( $context = 'view' ) { |
|
397 | + return $this->get_name( $context ); |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * Get the discount description. |
|
402 | + * |
|
403 | + * @since 1.0.19 |
|
404 | + * @param string $context View or edit context. |
|
405 | + * @return string |
|
406 | + */ |
|
407 | + public function get_description( $context = 'view' ) { |
|
408 | + return $this->get_prop( 'description', $context ); |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * Alias of self::get_description(). |
|
413 | + * |
|
414 | + * @since 1.0.19 |
|
415 | + * @param string $context View or edit context. |
|
416 | + * @return string |
|
417 | + */ |
|
418 | + public function get_excerpt( $context = 'view' ) { |
|
419 | + return $this->get_description( $context ); |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Alias of self::get_description(). |
|
424 | + * |
|
425 | + * @since 1.0.19 |
|
426 | + * @param string $context View or edit context. |
|
427 | + * @return string |
|
428 | + */ |
|
429 | + public function get_summary( $context = 'view' ) { |
|
430 | + return $this->get_description( $context ); |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * Get the owner of the discount. |
|
435 | + * |
|
436 | + * @since 1.0.19 |
|
437 | + * @param string $context View or edit context. |
|
438 | + * @return string |
|
439 | + */ |
|
440 | + public function get_author( $context = 'view' ) { |
|
441 | + return (int) $this->get_prop( 'author', $context ); |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * Get the discount code. |
|
446 | + * |
|
447 | + * @since 1.0.19 |
|
448 | + * @param string $context View or edit context. |
|
449 | + * @return string |
|
450 | + */ |
|
451 | + public function get_code( $context = 'view' ) { |
|
452 | + return $this->get_prop( 'code', $context ); |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Alias for self::get_code(). |
|
457 | + * |
|
458 | + * @since 1.0.19 |
|
459 | + * @param string $context View or edit context. |
|
460 | + * @return string |
|
461 | + */ |
|
462 | + public function get_coupon_code( $context = 'view' ) { |
|
463 | + return $this->get_code( $context ); |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * Alias for self::get_code(). |
|
468 | + * |
|
469 | + * @since 1.0.19 |
|
470 | + * @param string $context View or edit context. |
|
471 | + * @return string |
|
472 | + */ |
|
473 | + public function get_discount_code( $context = 'view' ) { |
|
474 | + return $this->get_code( $context ); |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * Get the discount's amount. |
|
479 | + * |
|
480 | + * @since 1.0.19 |
|
481 | + * @param string $context View or edit context. |
|
482 | + * @return float |
|
483 | + */ |
|
484 | + public function get_amount( $context = 'view' ) { |
|
485 | + return $context == 'view' ? floatval( $this->get_prop( 'amount', $context ) ) : $this->get_prop( 'amount', $context ); |
|
486 | + } |
|
487 | + |
|
488 | + /** |
|
489 | + * Get the discount's formated amount/rate. |
|
490 | + * |
|
491 | + * @since 1.0.19 |
|
492 | + * @return string |
|
493 | + */ |
|
494 | + public function get_formatted_amount() { |
|
495 | + |
|
496 | + if ( $this->is_type( 'flat' ) ) { |
|
497 | + $rate = wpinv_price( $this->get_amount() ); |
|
498 | + } else { |
|
499 | + $rate = $this->get_amount() . '%'; |
|
500 | + } |
|
501 | + |
|
502 | + return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() ); |
|
503 | + } |
|
504 | + |
|
505 | + /** |
|
506 | + * Get the discount's start date. |
|
507 | + * |
|
508 | + * @since 1.0.19 |
|
509 | + * @param string $context View or edit context. |
|
510 | + * @return string |
|
511 | + */ |
|
512 | + public function get_start( $context = 'view' ) { |
|
513 | + return $this->get_prop( 'start', $context ); |
|
514 | + } |
|
515 | + |
|
516 | + /** |
|
517 | + * Alias for self::get_start(). |
|
518 | + * |
|
519 | + * @since 1.0.19 |
|
520 | + * @param string $context View or edit context. |
|
521 | + * @return string |
|
522 | + */ |
|
523 | + public function get_start_date( $context = 'view' ) { |
|
524 | + return $this->get_start( $context ); |
|
525 | + } |
|
526 | + |
|
527 | + /** |
|
528 | + * Get the discount's expiration date. |
|
529 | + * |
|
530 | + * @since 1.0.19 |
|
531 | + * @param string $context View or edit context. |
|
532 | + * @return string |
|
533 | + */ |
|
534 | + public function get_expiration( $context = 'view' ) { |
|
535 | + return $this->get_prop( 'expiration', $context ); |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Alias for self::get_expiration(). |
|
540 | + * |
|
541 | + * @since 1.0.19 |
|
542 | + * @param string $context View or edit context. |
|
543 | + * @return string |
|
544 | + */ |
|
545 | + public function get_expiration_date( $context = 'view' ) { |
|
546 | + return $this->get_expiration( $context ); |
|
547 | + } |
|
548 | + |
|
549 | + /** |
|
550 | + * Alias for self::get_expiration(). |
|
551 | + * |
|
552 | + * @since 1.0.19 |
|
553 | + * @param string $context View or edit context. |
|
554 | + * @return string |
|
555 | + */ |
|
556 | + public function get_end_date( $context = 'view' ) { |
|
557 | + return $this->get_expiration( $context ); |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Get the discount's type. |
|
562 | + * |
|
563 | + * @since 1.0.19 |
|
564 | + * @param string $context View or edit context. |
|
565 | + * @return string |
|
566 | + */ |
|
567 | + public function get_type( $context = 'view' ) { |
|
568 | + return $this->get_prop( 'type', $context ); |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Get the number of times a discount has been used. |
|
573 | + * |
|
574 | + * @since 1.0.19 |
|
575 | + * @param string $context View or edit context. |
|
576 | + * @return int |
|
577 | + */ |
|
578 | + public function get_uses( $context = 'view' ) { |
|
579 | + return (int) $this->get_prop( 'uses', $context ); |
|
580 | + } |
|
581 | + |
|
582 | + /** |
|
583 | + * Get the discount's usage, i.e uses / max uses. |
|
584 | + * |
|
585 | + * @since 1.0.19 |
|
586 | + * @return string |
|
587 | + */ |
|
588 | + public function get_usage() { |
|
589 | + |
|
590 | + if ( ! $this->has_limit() ) { |
|
591 | + return $this->get_uses() . ' / ' . ' ∞'; |
|
592 | + } |
|
593 | + |
|
594 | + return $this->get_uses() . ' / ' . (int) $this->get_max_uses(); |
|
595 | + |
|
596 | + } |
|
597 | + |
|
598 | + /** |
|
599 | + * Get the maximum number of time a discount can be used. |
|
600 | + * |
|
601 | + * @since 1.0.19 |
|
602 | + * @param string $context View or edit context. |
|
603 | + * @return int |
|
604 | + */ |
|
605 | + public function get_max_uses( $context = 'view' ) { |
|
606 | + $max_uses = $this->get_prop( 'max_uses', $context ); |
|
607 | + return empty( $max_uses ) ? null : $max_uses; |
|
608 | + } |
|
609 | + |
|
610 | + /** |
|
611 | + * Checks if this is a single use discount or not. |
|
612 | + * |
|
613 | + * @since 1.0.19 |
|
614 | + * @param string $context View or edit context. |
|
615 | + * @return bool |
|
616 | + */ |
|
617 | + public function get_is_single_use( $context = 'view' ) { |
|
618 | + return $this->get_prop( 'is_single_use', $context ); |
|
619 | + } |
|
620 | + |
|
621 | + /** |
|
622 | + * Get the items that can be used with this discount. |
|
623 | + * |
|
624 | + * @since 1.0.19 |
|
625 | + * @param string $context View or edit context. |
|
626 | + * @return array |
|
627 | + */ |
|
628 | + public function get_items( $context = 'view' ) { |
|
629 | + return array_filter( wp_parse_id_list( $this->get_prop( 'items', $context ) ) ); |
|
630 | + } |
|
631 | + |
|
632 | + /** |
|
633 | + * Alias for self::get_items(). |
|
634 | + * |
|
635 | + * @since 1.0.19 |
|
636 | + * @param string $context View or edit context. |
|
637 | + * @return array |
|
638 | + */ |
|
639 | + public function get_allowed_items( $context = 'view' ) { |
|
640 | + return $this->get_items( $context ); |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * Get the items that are not allowed to use this discount. |
|
645 | + * |
|
646 | + * @since 1.0.19 |
|
647 | + * @param string $context View or edit context. |
|
648 | + * @return array |
|
649 | + */ |
|
650 | + public function get_excluded_items( $context = 'view' ) { |
|
651 | + return array_filter( wp_parse_id_list( $this->get_prop( 'excluded_items', $context ) ) ); |
|
652 | + } |
|
653 | + |
|
654 | + /** |
|
655 | + * Get the items that are required to be in the cart before using this discount. |
|
656 | + * |
|
657 | + * @since 1.0.19 |
|
658 | + * @param string $context View or edit context. |
|
659 | + * @return array |
|
660 | + */ |
|
661 | + public function get_required_items( $context = 'view' ) { |
|
662 | + return array_filter( wp_parse_id_list( $this->get_prop( 'required_items', $context ) ) ); |
|
663 | + } |
|
664 | + |
|
665 | + /** |
|
666 | + * Checks if this is a recurring discount or not. |
|
667 | + * |
|
668 | + * @since 1.0.19 |
|
669 | + * @param string $context View or edit context. |
|
670 | + * @return int|string|bool |
|
671 | + */ |
|
672 | + public function get_is_recurring( $context = 'view' ) { |
|
673 | + return $this->get_prop( 'is_recurring', $context ); |
|
674 | + } |
|
675 | + |
|
676 | + /** |
|
677 | + * Get's the minimum total amount allowed for this discount. |
|
678 | + * |
|
679 | + * @since 1.0.19 |
|
680 | + * @param string $context View or edit context. |
|
681 | + * @return float |
|
682 | + */ |
|
683 | + public function get_min_total( $context = 'view' ) { |
|
684 | + $minimum = $this->get_prop( 'min_total', $context ); |
|
685 | + return empty( $minimum ) ? null : $minimum; |
|
686 | + } |
|
687 | + |
|
688 | + /** |
|
689 | + * Alias for self::get_min_total(). |
|
690 | + * |
|
691 | + * @since 1.0.19 |
|
692 | + * @param string $context View or edit context. |
|
693 | + * @return float |
|
694 | + */ |
|
695 | + public function get_minimum_total( $context = 'view' ) { |
|
696 | + return $this->get_min_total( $context ); |
|
697 | + } |
|
698 | + |
|
699 | + /** |
|
700 | + * Get's the maximum total amount allowed for this discount. |
|
701 | + * |
|
702 | + * @since 1.0.19 |
|
703 | + * @param string $context View or edit context. |
|
704 | + * @return float |
|
705 | + */ |
|
706 | + public function get_max_total( $context = 'view' ) { |
|
707 | + $maximum = $this->get_prop( 'max_total', $context ); |
|
708 | + return empty( $maximum ) ? null : $maximum; |
|
709 | + } |
|
710 | + |
|
711 | + /** |
|
712 | + * Alias for self::get_max_total(). |
|
713 | + * |
|
714 | + * @since 1.0.19 |
|
715 | + * @param string $context View or edit context. |
|
716 | + * @return float |
|
717 | + */ |
|
718 | + public function get_maximum_total( $context = 'view' ) { |
|
719 | + return $this->get_max_total( $context ); |
|
720 | + } |
|
721 | + |
|
722 | + /** |
|
723 | + * Magic method for accessing discount properties. |
|
724 | + * |
|
725 | + * @since 1.0.15 |
|
726 | + * @access public |
|
727 | + * |
|
728 | + * @param string $key Discount data to retrieve |
|
729 | + * @param string $context View or edit context. |
|
730 | + * @return mixed Value of the given discount property (if set). |
|
731 | + */ |
|
732 | + public function get( $key, $context = 'view' ) { |
|
733 | 733 | return $this->get_prop( $key, $context ); |
734 | - } |
|
734 | + } |
|
735 | 735 | |
736 | - /* |
|
736 | + /* |
|
737 | 737 | |-------------------------------------------------------------------------- |
738 | 738 | | Setters |
739 | 739 | |-------------------------------------------------------------------------- |
@@ -743,41 +743,41 @@ discard block |
||
743 | 743 | | object. |
744 | 744 | */ |
745 | 745 | |
746 | - /** |
|
747 | - * Sets discount status. |
|
748 | - * |
|
749 | - * @since 1.0.19 |
|
750 | - * @param string $status New status. |
|
751 | - * @return array details of change. |
|
752 | - */ |
|
753 | - public function set_status( $status ) { |
|
746 | + /** |
|
747 | + * Sets discount status. |
|
748 | + * |
|
749 | + * @since 1.0.19 |
|
750 | + * @param string $status New status. |
|
751 | + * @return array details of change. |
|
752 | + */ |
|
753 | + public function set_status( $status ) { |
|
754 | 754 | $old_status = $this->get_status(); |
755 | 755 | |
756 | 756 | $this->set_prop( 'status', $status ); |
757 | 757 | |
758 | - return array( |
|
759 | - 'from' => $old_status, |
|
760 | - 'to' => $status, |
|
761 | - ); |
|
758 | + return array( |
|
759 | + 'from' => $old_status, |
|
760 | + 'to' => $status, |
|
761 | + ); |
|
762 | 762 | } |
763 | 763 | |
764 | 764 | /** |
765 | - * Set plugin version when the discount was created. |
|
766 | - * |
|
767 | - * @since 1.0.19 |
|
768 | - */ |
|
769 | - public function set_version( $value ) { |
|
770 | - $this->set_prop( 'version', $value ); |
|
765 | + * Set plugin version when the discount was created. |
|
766 | + * |
|
767 | + * @since 1.0.19 |
|
768 | + */ |
|
769 | + public function set_version( $value ) { |
|
770 | + $this->set_prop( 'version', $value ); |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | /** |
774 | - * Set date when the discount was created. |
|
775 | - * |
|
776 | - * @since 1.0.19 |
|
777 | - * @param string $value Value to set. |
|
774 | + * Set date when the discount was created. |
|
775 | + * |
|
776 | + * @since 1.0.19 |
|
777 | + * @param string $value Value to set. |
|
778 | 778 | * @return bool Whether or not the date was set. |
779 | - */ |
|
780 | - public function set_date_created( $value ) { |
|
779 | + */ |
|
780 | + public function set_date_created( $value ) { |
|
781 | 781 | $date = strtotime( $value ); |
782 | 782 | |
783 | 783 | if ( $date ) { |
@@ -790,13 +790,13 @@ discard block |
||
790 | 790 | } |
791 | 791 | |
792 | 792 | /** |
793 | - * Set date when the discount was last modified. |
|
794 | - * |
|
795 | - * @since 1.0.19 |
|
796 | - * @param string $value Value to set. |
|
793 | + * Set date when the discount was last modified. |
|
794 | + * |
|
795 | + * @since 1.0.19 |
|
796 | + * @param string $value Value to set. |
|
797 | 797 | * @return bool Whether or not the date was set. |
798 | - */ |
|
799 | - public function set_date_modified( $value ) { |
|
798 | + */ |
|
799 | + public function set_date_modified( $value ) { |
|
800 | 800 | $date = strtotime( $value ); |
801 | 801 | |
802 | 802 | if ( $date ) { |
@@ -809,334 +809,334 @@ discard block |
||
809 | 809 | } |
810 | 810 | |
811 | 811 | /** |
812 | - * Set the discount name. |
|
813 | - * |
|
814 | - * @since 1.0.19 |
|
815 | - * @param string $value New name. |
|
816 | - */ |
|
817 | - public function set_name( $value ) { |
|
812 | + * Set the discount name. |
|
813 | + * |
|
814 | + * @since 1.0.19 |
|
815 | + * @param string $value New name. |
|
816 | + */ |
|
817 | + public function set_name( $value ) { |
|
818 | 818 | $name = sanitize_text_field( $value ); |
819 | - $this->set_prop( 'name', $name ); |
|
819 | + $this->set_prop( 'name', $name ); |
|
820 | 820 | } |
821 | 821 | |
822 | 822 | /** |
823 | - * Alias of self::set_name(). |
|
824 | - * |
|
825 | - * @since 1.0.19 |
|
826 | - * @param string $value New name. |
|
827 | - */ |
|
828 | - public function set_title( $value ) { |
|
829 | - $this->set_name( $value ); |
|
823 | + * Alias of self::set_name(). |
|
824 | + * |
|
825 | + * @since 1.0.19 |
|
826 | + * @param string $value New name. |
|
827 | + */ |
|
828 | + public function set_title( $value ) { |
|
829 | + $this->set_name( $value ); |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | /** |
833 | - * Set the discount description. |
|
834 | - * |
|
835 | - * @since 1.0.19 |
|
836 | - * @param string $value New description. |
|
837 | - */ |
|
838 | - public function set_description( $value ) { |
|
833 | + * Set the discount description. |
|
834 | + * |
|
835 | + * @since 1.0.19 |
|
836 | + * @param string $value New description. |
|
837 | + */ |
|
838 | + public function set_description( $value ) { |
|
839 | 839 | $description = wp_kses_post( $value ); |
840 | - return $this->set_prop( 'description', $description ); |
|
841 | - } |
|
842 | - |
|
843 | - /** |
|
844 | - * Alias of self::set_description(). |
|
845 | - * |
|
846 | - * @since 1.0.19 |
|
847 | - * @param string $value New description. |
|
848 | - */ |
|
849 | - public function set_excerpt( $value ) { |
|
850 | - $this->set_description( $value ); |
|
851 | - } |
|
852 | - |
|
853 | - /** |
|
854 | - * Alias of self::set_description(). |
|
855 | - * |
|
856 | - * @since 1.0.19 |
|
857 | - * @param string $value New description. |
|
858 | - */ |
|
859 | - public function set_summary( $value ) { |
|
860 | - $this->set_description( $value ); |
|
861 | - } |
|
862 | - |
|
863 | - /** |
|
864 | - * Set the owner of the discount. |
|
865 | - * |
|
866 | - * @since 1.0.19 |
|
867 | - * @param int $value New author. |
|
868 | - */ |
|
869 | - public function set_author( $value ) { |
|
870 | - $this->set_prop( 'author', (int) $value ); |
|
871 | - } |
|
872 | - |
|
873 | - /** |
|
874 | - * Sets the discount code. |
|
875 | - * |
|
876 | - * @since 1.0.19 |
|
877 | - * @param string $value New discount code. |
|
878 | - */ |
|
879 | - public function set_code( $value ) { |
|
880 | - $code = sanitize_text_field( $value ); |
|
881 | - $this->set_prop( 'code', $code ); |
|
882 | - } |
|
883 | - |
|
884 | - /** |
|
885 | - * Alias of self::set_code(). |
|
886 | - * |
|
887 | - * @since 1.0.19 |
|
888 | - * @param string $value New discount code. |
|
889 | - */ |
|
890 | - public function set_coupon_code( $value ) { |
|
891 | - $this->set_code( $value ); |
|
892 | - } |
|
893 | - |
|
894 | - /** |
|
895 | - * Alias of self::set_code(). |
|
896 | - * |
|
897 | - * @since 1.0.19 |
|
898 | - * @param string $value New discount code. |
|
899 | - */ |
|
900 | - public function set_discount_code( $value ) { |
|
901 | - $this->set_code( $value ); |
|
902 | - } |
|
903 | - |
|
904 | - /** |
|
905 | - * Sets the discount amount. |
|
906 | - * |
|
907 | - * @since 1.0.19 |
|
908 | - * @param float $value New discount code. |
|
909 | - */ |
|
910 | - public function set_amount( $value ) { |
|
911 | - $amount = floatval( wpinv_sanitize_amount( $value ) ); |
|
912 | - $this->set_prop( 'amount', $amount ); |
|
913 | - } |
|
914 | - |
|
915 | - /** |
|
916 | - * Sets the discount's start date. |
|
917 | - * |
|
918 | - * @since 1.0.19 |
|
919 | - * @param float $value New start date. |
|
920 | - */ |
|
921 | - public function set_start( $value ) { |
|
922 | - $date = strtotime( $value ); |
|
840 | + return $this->set_prop( 'description', $description ); |
|
841 | + } |
|
842 | + |
|
843 | + /** |
|
844 | + * Alias of self::set_description(). |
|
845 | + * |
|
846 | + * @since 1.0.19 |
|
847 | + * @param string $value New description. |
|
848 | + */ |
|
849 | + public function set_excerpt( $value ) { |
|
850 | + $this->set_description( $value ); |
|
851 | + } |
|
852 | + |
|
853 | + /** |
|
854 | + * Alias of self::set_description(). |
|
855 | + * |
|
856 | + * @since 1.0.19 |
|
857 | + * @param string $value New description. |
|
858 | + */ |
|
859 | + public function set_summary( $value ) { |
|
860 | + $this->set_description( $value ); |
|
861 | + } |
|
862 | + |
|
863 | + /** |
|
864 | + * Set the owner of the discount. |
|
865 | + * |
|
866 | + * @since 1.0.19 |
|
867 | + * @param int $value New author. |
|
868 | + */ |
|
869 | + public function set_author( $value ) { |
|
870 | + $this->set_prop( 'author', (int) $value ); |
|
871 | + } |
|
872 | + |
|
873 | + /** |
|
874 | + * Sets the discount code. |
|
875 | + * |
|
876 | + * @since 1.0.19 |
|
877 | + * @param string $value New discount code. |
|
878 | + */ |
|
879 | + public function set_code( $value ) { |
|
880 | + $code = sanitize_text_field( $value ); |
|
881 | + $this->set_prop( 'code', $code ); |
|
882 | + } |
|
883 | + |
|
884 | + /** |
|
885 | + * Alias of self::set_code(). |
|
886 | + * |
|
887 | + * @since 1.0.19 |
|
888 | + * @param string $value New discount code. |
|
889 | + */ |
|
890 | + public function set_coupon_code( $value ) { |
|
891 | + $this->set_code( $value ); |
|
892 | + } |
|
893 | + |
|
894 | + /** |
|
895 | + * Alias of self::set_code(). |
|
896 | + * |
|
897 | + * @since 1.0.19 |
|
898 | + * @param string $value New discount code. |
|
899 | + */ |
|
900 | + public function set_discount_code( $value ) { |
|
901 | + $this->set_code( $value ); |
|
902 | + } |
|
903 | + |
|
904 | + /** |
|
905 | + * Sets the discount amount. |
|
906 | + * |
|
907 | + * @since 1.0.19 |
|
908 | + * @param float $value New discount code. |
|
909 | + */ |
|
910 | + public function set_amount( $value ) { |
|
911 | + $amount = floatval( wpinv_sanitize_amount( $value ) ); |
|
912 | + $this->set_prop( 'amount', $amount ); |
|
913 | + } |
|
914 | + |
|
915 | + /** |
|
916 | + * Sets the discount's start date. |
|
917 | + * |
|
918 | + * @since 1.0.19 |
|
919 | + * @param float $value New start date. |
|
920 | + */ |
|
921 | + public function set_start( $value ) { |
|
922 | + $date = strtotime( $value ); |
|
923 | 923 | |
924 | 924 | if ( $date ) { |
925 | 925 | $this->set_prop( 'start', date( 'Y-m-d H:i', $date ) ); |
926 | 926 | return true; |
927 | - } |
|
927 | + } |
|
928 | 928 | |
929 | - $this->set_prop( 'start', '' ); |
|
929 | + $this->set_prop( 'start', '' ); |
|
930 | 930 | |
931 | 931 | return false; |
932 | - } |
|
933 | - |
|
934 | - /** |
|
935 | - * Alias of self::set_start(). |
|
936 | - * |
|
937 | - * @since 1.0.19 |
|
938 | - * @param string $value New start date. |
|
939 | - */ |
|
940 | - public function set_start_date( $value ) { |
|
941 | - $this->set_start( $value ); |
|
942 | - } |
|
943 | - |
|
944 | - /** |
|
945 | - * Sets the discount's expiration date. |
|
946 | - * |
|
947 | - * @since 1.0.19 |
|
948 | - * @param float $value New expiration date. |
|
949 | - */ |
|
950 | - public function set_expiration( $value ) { |
|
951 | - $date = strtotime( $value ); |
|
932 | + } |
|
933 | + |
|
934 | + /** |
|
935 | + * Alias of self::set_start(). |
|
936 | + * |
|
937 | + * @since 1.0.19 |
|
938 | + * @param string $value New start date. |
|
939 | + */ |
|
940 | + public function set_start_date( $value ) { |
|
941 | + $this->set_start( $value ); |
|
942 | + } |
|
943 | + |
|
944 | + /** |
|
945 | + * Sets the discount's expiration date. |
|
946 | + * |
|
947 | + * @since 1.0.19 |
|
948 | + * @param float $value New expiration date. |
|
949 | + */ |
|
950 | + public function set_expiration( $value ) { |
|
951 | + $date = strtotime( $value ); |
|
952 | 952 | |
953 | 953 | if ( $date ) { |
954 | 954 | $this->set_prop( 'expiration', date( 'Y-m-d H:i', $date ) ); |
955 | 955 | return true; |
956 | 956 | } |
957 | 957 | |
958 | - $this->set_prop( 'expiration', '' ); |
|
958 | + $this->set_prop( 'expiration', '' ); |
|
959 | 959 | return false; |
960 | - } |
|
961 | - |
|
962 | - /** |
|
963 | - * Alias of self::set_expiration(). |
|
964 | - * |
|
965 | - * @since 1.0.19 |
|
966 | - * @param string $value New expiration date. |
|
967 | - */ |
|
968 | - public function set_expiration_date( $value ) { |
|
969 | - $this->set_expiration( $value ); |
|
970 | - } |
|
971 | - |
|
972 | - /** |
|
973 | - * Alias of self::set_expiration(). |
|
974 | - * |
|
975 | - * @since 1.0.19 |
|
976 | - * @param string $value New expiration date. |
|
977 | - */ |
|
978 | - public function set_end_date( $value ) { |
|
979 | - $this->set_expiration( $value ); |
|
980 | - } |
|
981 | - |
|
982 | - /** |
|
983 | - * Sets the discount type. |
|
984 | - * |
|
985 | - * @since 1.0.19 |
|
986 | - * @param string $value New discount type. |
|
987 | - */ |
|
988 | - public function set_type( $value ) { |
|
989 | - if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) { |
|
990 | - $this->set_prop( 'type', sanitize_text_field( $value ) ); |
|
991 | - } |
|
992 | - } |
|
993 | - |
|
994 | - /** |
|
995 | - * Sets the number of times a discount has been used. |
|
996 | - * |
|
997 | - * @since 1.0.19 |
|
998 | - * @param int $value usage count. |
|
999 | - */ |
|
1000 | - public function set_uses( $value ) { |
|
1001 | - |
|
1002 | - $value = (int) $value; |
|
1003 | - |
|
1004 | - if ( $value < 0 ) { |
|
1005 | - $value = 0; |
|
1006 | - } |
|
1007 | - |
|
1008 | - $this->set_prop( 'uses', (int) $value ); |
|
1009 | - } |
|
1010 | - |
|
1011 | - /** |
|
1012 | - * Sets the maximum number of times a discount can be used. |
|
1013 | - * |
|
1014 | - * @since 1.0.19 |
|
1015 | - * @param int $value maximum usage count. |
|
1016 | - */ |
|
1017 | - public function set_max_uses( $value ) { |
|
1018 | - $this->set_prop( 'max_uses', absint( $value ) ); |
|
1019 | - } |
|
1020 | - |
|
1021 | - /** |
|
1022 | - * Sets if this is a single use discount or not. |
|
1023 | - * |
|
1024 | - * @since 1.0.19 |
|
1025 | - * @param int|bool $value is single use. |
|
1026 | - */ |
|
1027 | - public function set_is_single_use( $value ) { |
|
1028 | - $this->set_prop( 'is_single_use', (bool) $value ); |
|
1029 | - } |
|
1030 | - |
|
1031 | - /** |
|
1032 | - * Sets the items that can be used with this discount. |
|
1033 | - * |
|
1034 | - * @since 1.0.19 |
|
1035 | - * @param array $value items. |
|
1036 | - */ |
|
1037 | - public function set_items( $value ) { |
|
1038 | - $this->set_prop( 'items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1039 | - } |
|
1040 | - |
|
1041 | - /** |
|
1042 | - * Alias for self::set_items(). |
|
1043 | - * |
|
1044 | - * @since 1.0.19 |
|
1045 | - * @param array $value items. |
|
1046 | - */ |
|
1047 | - public function set_allowed_items( $value ) { |
|
1048 | - $this->set_items( $value ); |
|
1049 | - } |
|
1050 | - |
|
1051 | - /** |
|
1052 | - * Sets the items that can not be used with this discount. |
|
1053 | - * |
|
1054 | - * @since 1.0.19 |
|
1055 | - * @param array $value items. |
|
1056 | - */ |
|
1057 | - public function set_excluded_items( $value ) { |
|
1058 | - $this->set_prop( 'excluded_items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1059 | - } |
|
1060 | - |
|
1061 | - /** |
|
1062 | - * Sets the items that are required to be in the cart before using this discount. |
|
1063 | - * |
|
1064 | - * @since 1.0.19 |
|
1065 | - * @param array $value items. |
|
1066 | - */ |
|
1067 | - public function set_required_items( $value ) { |
|
1068 | - $this->set_prop( 'required_items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1069 | - } |
|
1070 | - |
|
1071 | - /** |
|
1072 | - * Sets if this is a recurring discounts or not. |
|
1073 | - * |
|
1074 | - * @since 1.0.19 |
|
1075 | - * @param int|bool $value is recurring. |
|
1076 | - */ |
|
1077 | - public function set_is_recurring( $value ) { |
|
1078 | - $this->set_prop( 'is_recurring', (bool) $value ); |
|
1079 | - } |
|
1080 | - |
|
1081 | - /** |
|
1082 | - * Sets the minimum total that can not be used with this discount. |
|
1083 | - * |
|
1084 | - * @since 1.0.19 |
|
1085 | - * @param float $value minimum total. |
|
1086 | - */ |
|
1087 | - public function set_min_total( $value ) { |
|
1088 | - $this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1089 | - } |
|
1090 | - |
|
1091 | - /** |
|
1092 | - * Alias for self::set_min_total(). |
|
1093 | - * |
|
1094 | - * @since 1.0.19 |
|
1095 | - * @param float $value minimum total. |
|
1096 | - */ |
|
1097 | - public function set_minimum_total( $value ) { |
|
1098 | - $this->set_min_total( $value ); |
|
1099 | - } |
|
1100 | - |
|
1101 | - /** |
|
1102 | - * Sets the maximum total that can not be used with this discount. |
|
1103 | - * |
|
1104 | - * @since 1.0.19 |
|
1105 | - * @param float $value maximum total. |
|
1106 | - */ |
|
1107 | - public function set_max_total( $value ) { |
|
1108 | - $this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1109 | - } |
|
1110 | - |
|
1111 | - /** |
|
1112 | - * Alias for self::set_max_total(). |
|
1113 | - * |
|
1114 | - * @since 1.0.19 |
|
1115 | - * @param float $value maximum total. |
|
1116 | - */ |
|
1117 | - public function set_maximum_total( $value ) { |
|
1118 | - $this->set_max_total( $value ); |
|
1119 | - } |
|
1120 | - |
|
1121 | - /** |
|
1122 | - * @deprecated |
|
1123 | - */ |
|
1124 | - public function refresh(){} |
|
1125 | - |
|
1126 | - /** |
|
1127 | - * @deprecated |
|
1128 | - * |
|
1129 | - */ |
|
1130 | - public function update_status( $status = 'publish' ) { |
|
1131 | - |
|
1132 | - if ( $this->exists() && $this->get_status() != $status ) { |
|
1133 | - $this->set_status( $status ); |
|
1134 | - $this->save(); |
|
1135 | - } |
|
1136 | - |
|
1137 | - } |
|
1138 | - |
|
1139 | - /* |
|
960 | + } |
|
961 | + |
|
962 | + /** |
|
963 | + * Alias of self::set_expiration(). |
|
964 | + * |
|
965 | + * @since 1.0.19 |
|
966 | + * @param string $value New expiration date. |
|
967 | + */ |
|
968 | + public function set_expiration_date( $value ) { |
|
969 | + $this->set_expiration( $value ); |
|
970 | + } |
|
971 | + |
|
972 | + /** |
|
973 | + * Alias of self::set_expiration(). |
|
974 | + * |
|
975 | + * @since 1.0.19 |
|
976 | + * @param string $value New expiration date. |
|
977 | + */ |
|
978 | + public function set_end_date( $value ) { |
|
979 | + $this->set_expiration( $value ); |
|
980 | + } |
|
981 | + |
|
982 | + /** |
|
983 | + * Sets the discount type. |
|
984 | + * |
|
985 | + * @since 1.0.19 |
|
986 | + * @param string $value New discount type. |
|
987 | + */ |
|
988 | + public function set_type( $value ) { |
|
989 | + if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) { |
|
990 | + $this->set_prop( 'type', sanitize_text_field( $value ) ); |
|
991 | + } |
|
992 | + } |
|
993 | + |
|
994 | + /** |
|
995 | + * Sets the number of times a discount has been used. |
|
996 | + * |
|
997 | + * @since 1.0.19 |
|
998 | + * @param int $value usage count. |
|
999 | + */ |
|
1000 | + public function set_uses( $value ) { |
|
1001 | + |
|
1002 | + $value = (int) $value; |
|
1003 | + |
|
1004 | + if ( $value < 0 ) { |
|
1005 | + $value = 0; |
|
1006 | + } |
|
1007 | + |
|
1008 | + $this->set_prop( 'uses', (int) $value ); |
|
1009 | + } |
|
1010 | + |
|
1011 | + /** |
|
1012 | + * Sets the maximum number of times a discount can be used. |
|
1013 | + * |
|
1014 | + * @since 1.0.19 |
|
1015 | + * @param int $value maximum usage count. |
|
1016 | + */ |
|
1017 | + public function set_max_uses( $value ) { |
|
1018 | + $this->set_prop( 'max_uses', absint( $value ) ); |
|
1019 | + } |
|
1020 | + |
|
1021 | + /** |
|
1022 | + * Sets if this is a single use discount or not. |
|
1023 | + * |
|
1024 | + * @since 1.0.19 |
|
1025 | + * @param int|bool $value is single use. |
|
1026 | + */ |
|
1027 | + public function set_is_single_use( $value ) { |
|
1028 | + $this->set_prop( 'is_single_use', (bool) $value ); |
|
1029 | + } |
|
1030 | + |
|
1031 | + /** |
|
1032 | + * Sets the items that can be used with this discount. |
|
1033 | + * |
|
1034 | + * @since 1.0.19 |
|
1035 | + * @param array $value items. |
|
1036 | + */ |
|
1037 | + public function set_items( $value ) { |
|
1038 | + $this->set_prop( 'items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1039 | + } |
|
1040 | + |
|
1041 | + /** |
|
1042 | + * Alias for self::set_items(). |
|
1043 | + * |
|
1044 | + * @since 1.0.19 |
|
1045 | + * @param array $value items. |
|
1046 | + */ |
|
1047 | + public function set_allowed_items( $value ) { |
|
1048 | + $this->set_items( $value ); |
|
1049 | + } |
|
1050 | + |
|
1051 | + /** |
|
1052 | + * Sets the items that can not be used with this discount. |
|
1053 | + * |
|
1054 | + * @since 1.0.19 |
|
1055 | + * @param array $value items. |
|
1056 | + */ |
|
1057 | + public function set_excluded_items( $value ) { |
|
1058 | + $this->set_prop( 'excluded_items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1059 | + } |
|
1060 | + |
|
1061 | + /** |
|
1062 | + * Sets the items that are required to be in the cart before using this discount. |
|
1063 | + * |
|
1064 | + * @since 1.0.19 |
|
1065 | + * @param array $value items. |
|
1066 | + */ |
|
1067 | + public function set_required_items( $value ) { |
|
1068 | + $this->set_prop( 'required_items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1069 | + } |
|
1070 | + |
|
1071 | + /** |
|
1072 | + * Sets if this is a recurring discounts or not. |
|
1073 | + * |
|
1074 | + * @since 1.0.19 |
|
1075 | + * @param int|bool $value is recurring. |
|
1076 | + */ |
|
1077 | + public function set_is_recurring( $value ) { |
|
1078 | + $this->set_prop( 'is_recurring', (bool) $value ); |
|
1079 | + } |
|
1080 | + |
|
1081 | + /** |
|
1082 | + * Sets the minimum total that can not be used with this discount. |
|
1083 | + * |
|
1084 | + * @since 1.0.19 |
|
1085 | + * @param float $value minimum total. |
|
1086 | + */ |
|
1087 | + public function set_min_total( $value ) { |
|
1088 | + $this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1089 | + } |
|
1090 | + |
|
1091 | + /** |
|
1092 | + * Alias for self::set_min_total(). |
|
1093 | + * |
|
1094 | + * @since 1.0.19 |
|
1095 | + * @param float $value minimum total. |
|
1096 | + */ |
|
1097 | + public function set_minimum_total( $value ) { |
|
1098 | + $this->set_min_total( $value ); |
|
1099 | + } |
|
1100 | + |
|
1101 | + /** |
|
1102 | + * Sets the maximum total that can not be used with this discount. |
|
1103 | + * |
|
1104 | + * @since 1.0.19 |
|
1105 | + * @param float $value maximum total. |
|
1106 | + */ |
|
1107 | + public function set_max_total( $value ) { |
|
1108 | + $this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1109 | + } |
|
1110 | + |
|
1111 | + /** |
|
1112 | + * Alias for self::set_max_total(). |
|
1113 | + * |
|
1114 | + * @since 1.0.19 |
|
1115 | + * @param float $value maximum total. |
|
1116 | + */ |
|
1117 | + public function set_maximum_total( $value ) { |
|
1118 | + $this->set_max_total( $value ); |
|
1119 | + } |
|
1120 | + |
|
1121 | + /** |
|
1122 | + * @deprecated |
|
1123 | + */ |
|
1124 | + public function refresh(){} |
|
1125 | + |
|
1126 | + /** |
|
1127 | + * @deprecated |
|
1128 | + * |
|
1129 | + */ |
|
1130 | + public function update_status( $status = 'publish' ) { |
|
1131 | + |
|
1132 | + if ( $this->exists() && $this->get_status() != $status ) { |
|
1133 | + $this->set_status( $status ); |
|
1134 | + $this->save(); |
|
1135 | + } |
|
1136 | + |
|
1137 | + } |
|
1138 | + |
|
1139 | + /* |
|
1140 | 1140 | |-------------------------------------------------------------------------- |
1141 | 1141 | | Conditionals |
1142 | 1142 | |-------------------------------------------------------------------------- |
@@ -1145,290 +1145,290 @@ discard block |
||
1145 | 1145 | | |
1146 | 1146 | */ |
1147 | 1147 | |
1148 | - /** |
|
1149 | - * Checks whether a discount exists in the database or not |
|
1150 | - * |
|
1151 | - * @since 1.0.15 |
|
1152 | - */ |
|
1153 | - public function exists() { |
|
1154 | - $id = $this->get_id(); |
|
1155 | - return ! empty( $id ); |
|
1156 | - } |
|
1157 | - |
|
1158 | - /** |
|
1159 | - * Checks the discount type. |
|
1160 | - * |
|
1161 | - * |
|
1162 | - * @param string $type the discount type to check against |
|
1163 | - * @since 1.0.15 |
|
1164 | - * @return bool |
|
1165 | - */ |
|
1166 | - public function is_type( $type ) { |
|
1167 | - return $this->get_type() == $type; |
|
1168 | - } |
|
1169 | - |
|
1170 | - /** |
|
1171 | - * Checks whether the discount is published or not |
|
1172 | - * |
|
1173 | - * @since 1.0.15 |
|
1174 | - * @return bool |
|
1175 | - */ |
|
1176 | - public function is_active() { |
|
1177 | - return $this->get_status() == 'publish'; |
|
1178 | - } |
|
1179 | - |
|
1180 | - /** |
|
1181 | - * Checks whether the discount has max uses |
|
1182 | - * |
|
1183 | - * @since 1.0.15 |
|
1184 | - * @return bool |
|
1185 | - */ |
|
1186 | - public function has_limit() { |
|
1187 | - $limit = $this->get_max_uses(); |
|
1188 | - return ! empty( $limit ); |
|
1189 | - } |
|
1190 | - |
|
1191 | - /** |
|
1192 | - * Checks whether the discount has ever been used. |
|
1193 | - * |
|
1194 | - * @since 1.0.15 |
|
1195 | - * @return bool |
|
1196 | - */ |
|
1197 | - public function has_uses() { |
|
1198 | - return $this->get_uses() > 0; |
|
1199 | - } |
|
1200 | - |
|
1201 | - /** |
|
1202 | - * Checks whether the discount is has exided the usage limit or not |
|
1203 | - * |
|
1204 | - * @since 1.0.15 |
|
1205 | - * @return bool |
|
1206 | - */ |
|
1207 | - public function has_exceeded_limit() { |
|
1208 | - |
|
1209 | - if ( ! $this->has_limit() || ! $this->has_uses() ) { |
|
1210 | - $exceeded = false; |
|
1211 | - } else { |
|
1212 | - $exceeded = (int) $this->get_max_uses() <= $this->get_uses(); |
|
1213 | - } |
|
1214 | - |
|
1215 | - return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->get_id(), $this, $this->get_code() ); |
|
1216 | - } |
|
1217 | - |
|
1218 | - /** |
|
1219 | - * Checks whether the discount has an expiration date. |
|
1220 | - * |
|
1221 | - * @since 1.0.15 |
|
1222 | - * @return bool |
|
1223 | - */ |
|
1224 | - public function has_expiration_date() { |
|
1225 | - $date = $this->get_expiration_date(); |
|
1226 | - return ! empty( $date ); |
|
1227 | - } |
|
1228 | - |
|
1229 | - /** |
|
1230 | - * Checks if the discount is expired |
|
1231 | - * |
|
1232 | - * @since 1.0.15 |
|
1233 | - * @return bool |
|
1234 | - */ |
|
1235 | - public function is_expired() { |
|
1236 | - $expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false; |
|
1237 | - return apply_filters( 'wpinv_is_discount_expired', $expired, $this->get_id(), $this, $this->get_code() ); |
|
1238 | - } |
|
1239 | - |
|
1240 | - /** |
|
1241 | - * Checks whether the discount has a start date. |
|
1242 | - * |
|
1243 | - * @since 1.0.15 |
|
1244 | - * @return bool |
|
1245 | - */ |
|
1246 | - public function has_start_date() { |
|
1247 | - $date = $this->get_start_date(); |
|
1248 | - return ! empty( $date ); |
|
1249 | - } |
|
1250 | - |
|
1251 | - /** |
|
1252 | - * Checks the discount start date. |
|
1253 | - * |
|
1254 | - * @since 1.0.15 |
|
1255 | - * @return bool |
|
1256 | - */ |
|
1257 | - public function has_started() { |
|
1258 | - $started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() ); |
|
1259 | - return apply_filters( 'wpinv_is_discount_started', $started, $this->get_id(), $this, $this->get_code() ); |
|
1260 | - } |
|
1261 | - |
|
1262 | - /** |
|
1263 | - * Checks the discount has allowed items or not. |
|
1264 | - * |
|
1265 | - * @since 1.0.15 |
|
1266 | - * @return bool |
|
1267 | - */ |
|
1268 | - public function has_allowed_items() { |
|
1269 | - $allowed_items = $this->get_allowed_items(); |
|
1270 | - return ! empty( $allowed_items ); |
|
1271 | - } |
|
1272 | - |
|
1273 | - /** |
|
1274 | - * Checks the discount has excluded items or not. |
|
1275 | - * |
|
1276 | - * @since 1.0.15 |
|
1277 | - * @return bool |
|
1278 | - */ |
|
1279 | - public function has_excluded_items() { |
|
1280 | - $excluded_items = $this->get_excluded_items(); |
|
1281 | - return ! empty( $excluded_items ); |
|
1282 | - } |
|
1283 | - |
|
1284 | - /** |
|
1285 | - * Check if a discount is valid for a given item id. |
|
1286 | - * |
|
1287 | - * @param int|int[] $item_ids |
|
1288 | - * @since 1.0.15 |
|
1289 | - * @return boolean |
|
1290 | - */ |
|
1291 | - public function is_valid_for_items( $item_ids ) { |
|
1292 | - |
|
1293 | - $item_ids = array_filter( wp_parse_id_list( $item_ids ) ); |
|
1294 | - $included = array_intersect( $item_ids, $this->get_allowed_items() ); |
|
1295 | - $excluded = array_intersect( $item_ids, $this->get_excluded_items() ); |
|
1296 | - |
|
1297 | - if ( $this->has_excluded_items() && ! empty( $excluded ) ) { |
|
1298 | - return false; |
|
1299 | - } |
|
1300 | - |
|
1301 | - if ( $this->has_allowed_items() && empty( $included ) ) { |
|
1302 | - return false; |
|
1303 | - } |
|
1304 | - |
|
1305 | - return true; |
|
1306 | - } |
|
1307 | - |
|
1308 | - /** |
|
1309 | - * Checks the discount has required items or not. |
|
1310 | - * |
|
1311 | - * @since 1.0.15 |
|
1312 | - * @return bool |
|
1313 | - */ |
|
1314 | - public function has_required_items() { |
|
1315 | - $required_items = $this->get_required_items(); |
|
1316 | - return ! empty( $required_items ); |
|
1317 | - } |
|
1318 | - |
|
1319 | - /** |
|
1320 | - * Checks if the required items are met |
|
1321 | - * |
|
1322 | - * @param int|int[] $item_ids |
|
1323 | - * @since 1.0.15 |
|
1324 | - * @return boolean |
|
1325 | - */ |
|
1326 | - public function is_required_items_met( $item_ids ) { |
|
1327 | - |
|
1328 | - if ( ! $this->has_required_items() ) { |
|
1329 | - return true; |
|
1330 | - } |
|
1331 | - |
|
1332 | - return ! array_diff( $this->get_required_items(), array_filter( wp_parse_id_list( $item_ids ) ) ); |
|
1333 | - } |
|
1334 | - |
|
1335 | - /** |
|
1336 | - * Check if a discount is valid for the given amount |
|
1337 | - * |
|
1338 | - * @param float $amount The amount to check against |
|
1339 | - * @since 1.0.15 |
|
1340 | - * @return boolean |
|
1341 | - */ |
|
1342 | - public function is_valid_for_amount( $amount ) { |
|
1343 | - return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount ); |
|
1344 | - } |
|
1345 | - |
|
1346 | - /** |
|
1347 | - * Checks if the minimum amount is set |
|
1348 | - * |
|
1349 | - * @since 1.0.15 |
|
1350 | - * @return boolean |
|
1351 | - */ |
|
1352 | - public function has_minimum_amount() { |
|
1353 | - $minimum = $this->get_minimum_total(); |
|
1354 | - return ! empty( $minimum ); |
|
1355 | - } |
|
1356 | - |
|
1357 | - /** |
|
1358 | - * Checks if the minimum amount is met |
|
1359 | - * |
|
1360 | - * @param float $amount The amount to check against |
|
1361 | - * @since 1.0.15 |
|
1362 | - * @return boolean |
|
1363 | - */ |
|
1364 | - public function is_minimum_amount_met( $amount ) { |
|
1365 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1366 | - $min_met = ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) ); |
|
1367 | - return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1368 | - } |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * Checks if the maximum amount is set |
|
1372 | - * |
|
1373 | - * @since 1.0.15 |
|
1374 | - * @return boolean |
|
1375 | - */ |
|
1376 | - public function has_maximum_amount() { |
|
1377 | - $maximum = $this->get_maximum_total(); |
|
1378 | - return ! empty( $maximum ); |
|
1379 | - } |
|
1380 | - |
|
1381 | - /** |
|
1382 | - * Checks if the maximum amount is met |
|
1383 | - * |
|
1384 | - * @param float $amount The amount to check against |
|
1385 | - * @since 1.0.15 |
|
1386 | - * @return boolean |
|
1387 | - */ |
|
1388 | - public function is_maximum_amount_met( $amount ) { |
|
1389 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1390 | - $max_met = ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) ); |
|
1391 | - return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1392 | - } |
|
1393 | - |
|
1394 | - /** |
|
1395 | - * Checks if the discount is recurring. |
|
1396 | - * |
|
1397 | - * @since 1.0.15 |
|
1398 | - * @return boolean |
|
1399 | - */ |
|
1400 | - public function is_recurring() { |
|
1401 | - $recurring = $this->get_is_recurring(); |
|
1402 | - return ! empty( $recurring ); |
|
1403 | - } |
|
1404 | - |
|
1405 | - /** |
|
1406 | - * Checks if the discount is single use. |
|
1407 | - * |
|
1408 | - * @since 1.0.15 |
|
1409 | - * @return boolean |
|
1410 | - */ |
|
1411 | - public function is_single_use() { |
|
1412 | - $usage = $this->get_is_single_use(); |
|
1413 | - return ! empty( $usage ); |
|
1414 | - } |
|
1415 | - |
|
1416 | - /** |
|
1417 | - * Check if a discount is valid for the given user |
|
1418 | - * |
|
1419 | - * @param int|string $user |
|
1420 | - * @since 1.0.15 |
|
1421 | - * @return boolean |
|
1422 | - */ |
|
1423 | - public function is_valid_for_user( $user ) { |
|
1424 | - |
|
1425 | - // Ensure that the discount is single use. |
|
1426 | - if ( empty( $user ) || ! $this->is_single_use() ) { |
|
1427 | - return true; |
|
1428 | - } |
|
1429 | - |
|
1430 | - // Prepare the user id. |
|
1431 | - $user_id = 0; |
|
1148 | + /** |
|
1149 | + * Checks whether a discount exists in the database or not |
|
1150 | + * |
|
1151 | + * @since 1.0.15 |
|
1152 | + */ |
|
1153 | + public function exists() { |
|
1154 | + $id = $this->get_id(); |
|
1155 | + return ! empty( $id ); |
|
1156 | + } |
|
1157 | + |
|
1158 | + /** |
|
1159 | + * Checks the discount type. |
|
1160 | + * |
|
1161 | + * |
|
1162 | + * @param string $type the discount type to check against |
|
1163 | + * @since 1.0.15 |
|
1164 | + * @return bool |
|
1165 | + */ |
|
1166 | + public function is_type( $type ) { |
|
1167 | + return $this->get_type() == $type; |
|
1168 | + } |
|
1169 | + |
|
1170 | + /** |
|
1171 | + * Checks whether the discount is published or not |
|
1172 | + * |
|
1173 | + * @since 1.0.15 |
|
1174 | + * @return bool |
|
1175 | + */ |
|
1176 | + public function is_active() { |
|
1177 | + return $this->get_status() == 'publish'; |
|
1178 | + } |
|
1179 | + |
|
1180 | + /** |
|
1181 | + * Checks whether the discount has max uses |
|
1182 | + * |
|
1183 | + * @since 1.0.15 |
|
1184 | + * @return bool |
|
1185 | + */ |
|
1186 | + public function has_limit() { |
|
1187 | + $limit = $this->get_max_uses(); |
|
1188 | + return ! empty( $limit ); |
|
1189 | + } |
|
1190 | + |
|
1191 | + /** |
|
1192 | + * Checks whether the discount has ever been used. |
|
1193 | + * |
|
1194 | + * @since 1.0.15 |
|
1195 | + * @return bool |
|
1196 | + */ |
|
1197 | + public function has_uses() { |
|
1198 | + return $this->get_uses() > 0; |
|
1199 | + } |
|
1200 | + |
|
1201 | + /** |
|
1202 | + * Checks whether the discount is has exided the usage limit or not |
|
1203 | + * |
|
1204 | + * @since 1.0.15 |
|
1205 | + * @return bool |
|
1206 | + */ |
|
1207 | + public function has_exceeded_limit() { |
|
1208 | + |
|
1209 | + if ( ! $this->has_limit() || ! $this->has_uses() ) { |
|
1210 | + $exceeded = false; |
|
1211 | + } else { |
|
1212 | + $exceeded = (int) $this->get_max_uses() <= $this->get_uses(); |
|
1213 | + } |
|
1214 | + |
|
1215 | + return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->get_id(), $this, $this->get_code() ); |
|
1216 | + } |
|
1217 | + |
|
1218 | + /** |
|
1219 | + * Checks whether the discount has an expiration date. |
|
1220 | + * |
|
1221 | + * @since 1.0.15 |
|
1222 | + * @return bool |
|
1223 | + */ |
|
1224 | + public function has_expiration_date() { |
|
1225 | + $date = $this->get_expiration_date(); |
|
1226 | + return ! empty( $date ); |
|
1227 | + } |
|
1228 | + |
|
1229 | + /** |
|
1230 | + * Checks if the discount is expired |
|
1231 | + * |
|
1232 | + * @since 1.0.15 |
|
1233 | + * @return bool |
|
1234 | + */ |
|
1235 | + public function is_expired() { |
|
1236 | + $expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false; |
|
1237 | + return apply_filters( 'wpinv_is_discount_expired', $expired, $this->get_id(), $this, $this->get_code() ); |
|
1238 | + } |
|
1239 | + |
|
1240 | + /** |
|
1241 | + * Checks whether the discount has a start date. |
|
1242 | + * |
|
1243 | + * @since 1.0.15 |
|
1244 | + * @return bool |
|
1245 | + */ |
|
1246 | + public function has_start_date() { |
|
1247 | + $date = $this->get_start_date(); |
|
1248 | + return ! empty( $date ); |
|
1249 | + } |
|
1250 | + |
|
1251 | + /** |
|
1252 | + * Checks the discount start date. |
|
1253 | + * |
|
1254 | + * @since 1.0.15 |
|
1255 | + * @return bool |
|
1256 | + */ |
|
1257 | + public function has_started() { |
|
1258 | + $started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() ); |
|
1259 | + return apply_filters( 'wpinv_is_discount_started', $started, $this->get_id(), $this, $this->get_code() ); |
|
1260 | + } |
|
1261 | + |
|
1262 | + /** |
|
1263 | + * Checks the discount has allowed items or not. |
|
1264 | + * |
|
1265 | + * @since 1.0.15 |
|
1266 | + * @return bool |
|
1267 | + */ |
|
1268 | + public function has_allowed_items() { |
|
1269 | + $allowed_items = $this->get_allowed_items(); |
|
1270 | + return ! empty( $allowed_items ); |
|
1271 | + } |
|
1272 | + |
|
1273 | + /** |
|
1274 | + * Checks the discount has excluded items or not. |
|
1275 | + * |
|
1276 | + * @since 1.0.15 |
|
1277 | + * @return bool |
|
1278 | + */ |
|
1279 | + public function has_excluded_items() { |
|
1280 | + $excluded_items = $this->get_excluded_items(); |
|
1281 | + return ! empty( $excluded_items ); |
|
1282 | + } |
|
1283 | + |
|
1284 | + /** |
|
1285 | + * Check if a discount is valid for a given item id. |
|
1286 | + * |
|
1287 | + * @param int|int[] $item_ids |
|
1288 | + * @since 1.0.15 |
|
1289 | + * @return boolean |
|
1290 | + */ |
|
1291 | + public function is_valid_for_items( $item_ids ) { |
|
1292 | + |
|
1293 | + $item_ids = array_filter( wp_parse_id_list( $item_ids ) ); |
|
1294 | + $included = array_intersect( $item_ids, $this->get_allowed_items() ); |
|
1295 | + $excluded = array_intersect( $item_ids, $this->get_excluded_items() ); |
|
1296 | + |
|
1297 | + if ( $this->has_excluded_items() && ! empty( $excluded ) ) { |
|
1298 | + return false; |
|
1299 | + } |
|
1300 | + |
|
1301 | + if ( $this->has_allowed_items() && empty( $included ) ) { |
|
1302 | + return false; |
|
1303 | + } |
|
1304 | + |
|
1305 | + return true; |
|
1306 | + } |
|
1307 | + |
|
1308 | + /** |
|
1309 | + * Checks the discount has required items or not. |
|
1310 | + * |
|
1311 | + * @since 1.0.15 |
|
1312 | + * @return bool |
|
1313 | + */ |
|
1314 | + public function has_required_items() { |
|
1315 | + $required_items = $this->get_required_items(); |
|
1316 | + return ! empty( $required_items ); |
|
1317 | + } |
|
1318 | + |
|
1319 | + /** |
|
1320 | + * Checks if the required items are met |
|
1321 | + * |
|
1322 | + * @param int|int[] $item_ids |
|
1323 | + * @since 1.0.15 |
|
1324 | + * @return boolean |
|
1325 | + */ |
|
1326 | + public function is_required_items_met( $item_ids ) { |
|
1327 | + |
|
1328 | + if ( ! $this->has_required_items() ) { |
|
1329 | + return true; |
|
1330 | + } |
|
1331 | + |
|
1332 | + return ! array_diff( $this->get_required_items(), array_filter( wp_parse_id_list( $item_ids ) ) ); |
|
1333 | + } |
|
1334 | + |
|
1335 | + /** |
|
1336 | + * Check if a discount is valid for the given amount |
|
1337 | + * |
|
1338 | + * @param float $amount The amount to check against |
|
1339 | + * @since 1.0.15 |
|
1340 | + * @return boolean |
|
1341 | + */ |
|
1342 | + public function is_valid_for_amount( $amount ) { |
|
1343 | + return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount ); |
|
1344 | + } |
|
1345 | + |
|
1346 | + /** |
|
1347 | + * Checks if the minimum amount is set |
|
1348 | + * |
|
1349 | + * @since 1.0.15 |
|
1350 | + * @return boolean |
|
1351 | + */ |
|
1352 | + public function has_minimum_amount() { |
|
1353 | + $minimum = $this->get_minimum_total(); |
|
1354 | + return ! empty( $minimum ); |
|
1355 | + } |
|
1356 | + |
|
1357 | + /** |
|
1358 | + * Checks if the minimum amount is met |
|
1359 | + * |
|
1360 | + * @param float $amount The amount to check against |
|
1361 | + * @since 1.0.15 |
|
1362 | + * @return boolean |
|
1363 | + */ |
|
1364 | + public function is_minimum_amount_met( $amount ) { |
|
1365 | + $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1366 | + $min_met = ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) ); |
|
1367 | + return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1368 | + } |
|
1369 | + |
|
1370 | + /** |
|
1371 | + * Checks if the maximum amount is set |
|
1372 | + * |
|
1373 | + * @since 1.0.15 |
|
1374 | + * @return boolean |
|
1375 | + */ |
|
1376 | + public function has_maximum_amount() { |
|
1377 | + $maximum = $this->get_maximum_total(); |
|
1378 | + return ! empty( $maximum ); |
|
1379 | + } |
|
1380 | + |
|
1381 | + /** |
|
1382 | + * Checks if the maximum amount is met |
|
1383 | + * |
|
1384 | + * @param float $amount The amount to check against |
|
1385 | + * @since 1.0.15 |
|
1386 | + * @return boolean |
|
1387 | + */ |
|
1388 | + public function is_maximum_amount_met( $amount ) { |
|
1389 | + $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1390 | + $max_met = ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) ); |
|
1391 | + return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1392 | + } |
|
1393 | + |
|
1394 | + /** |
|
1395 | + * Checks if the discount is recurring. |
|
1396 | + * |
|
1397 | + * @since 1.0.15 |
|
1398 | + * @return boolean |
|
1399 | + */ |
|
1400 | + public function is_recurring() { |
|
1401 | + $recurring = $this->get_is_recurring(); |
|
1402 | + return ! empty( $recurring ); |
|
1403 | + } |
|
1404 | + |
|
1405 | + /** |
|
1406 | + * Checks if the discount is single use. |
|
1407 | + * |
|
1408 | + * @since 1.0.15 |
|
1409 | + * @return boolean |
|
1410 | + */ |
|
1411 | + public function is_single_use() { |
|
1412 | + $usage = $this->get_is_single_use(); |
|
1413 | + return ! empty( $usage ); |
|
1414 | + } |
|
1415 | + |
|
1416 | + /** |
|
1417 | + * Check if a discount is valid for the given user |
|
1418 | + * |
|
1419 | + * @param int|string $user |
|
1420 | + * @since 1.0.15 |
|
1421 | + * @return boolean |
|
1422 | + */ |
|
1423 | + public function is_valid_for_user( $user ) { |
|
1424 | + |
|
1425 | + // Ensure that the discount is single use. |
|
1426 | + if ( empty( $user ) || ! $this->is_single_use() ) { |
|
1427 | + return true; |
|
1428 | + } |
|
1429 | + |
|
1430 | + // Prepare the user id. |
|
1431 | + $user_id = 0; |
|
1432 | 1432 | if ( is_numeric( $user ) ) { |
1433 | 1433 | $user_id = absint( $user ); |
1434 | 1434 | } elseif ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
@@ -1437,122 +1437,122 @@ discard block |
||
1437 | 1437 | $user_id = $user_data->ID; |
1438 | 1438 | } |
1439 | 1439 | |
1440 | - // Ensure that we have a user. |
|
1441 | - if ( empty( $user_id ) ) { |
|
1442 | - return true; |
|
1443 | - } |
|
1440 | + // Ensure that we have a user. |
|
1441 | + if ( empty( $user_id ) ) { |
|
1442 | + return true; |
|
1443 | + } |
|
1444 | 1444 | |
1445 | - // Get all payments with matching user id. |
|
1445 | + // Get all payments with matching user id. |
|
1446 | 1446 | $payments = wpinv_get_invoices( |
1447 | 1447 | array( |
1448 | - 'user' => $user_id, |
|
1449 | - 'limit' => false, |
|
1450 | - 'paginate' => false, |
|
1448 | + 'user' => $user_id, |
|
1449 | + 'limit' => false, |
|
1450 | + 'paginate' => false, |
|
1451 | 1451 | ) |
1452 | 1452 | ); |
1453 | - $code = strtolower( $this->get_code() ); |
|
1453 | + $code = strtolower( $this->get_code() ); |
|
1454 | 1454 | |
1455 | - // For each payment... |
|
1456 | - foreach ( $payments as $payment ) { |
|
1455 | + // For each payment... |
|
1456 | + foreach ( $payments as $payment ) { |
|
1457 | 1457 | |
1458 | - // Only check for paid invoices. |
|
1459 | - if ( $payment->is_paid() && strtolower( $payment->get_discount_code() ) == $code ) { |
|
1460 | - return false; |
|
1461 | - } |
|
1458 | + // Only check for paid invoices. |
|
1459 | + if ( $payment->is_paid() && strtolower( $payment->get_discount_code() ) == $code ) { |
|
1460 | + return false; |
|
1461 | + } |
|
1462 | 1462 | } |
1463 | 1463 | |
1464 | - return true; |
|
1465 | - } |
|
1466 | - |
|
1467 | - /** |
|
1468 | - * Deletes the discount from the database |
|
1469 | - * |
|
1470 | - * @since 1.0.15 |
|
1471 | - * @return boolean |
|
1472 | - */ |
|
1473 | - public function remove() { |
|
1474 | - return $this->delete(); |
|
1475 | - } |
|
1476 | - |
|
1477 | - /** |
|
1478 | - * Increases a discount's usage. |
|
1479 | - * |
|
1480 | - * @since 1.0.15 |
|
1481 | - * @param int $by The number of usages to increas by. |
|
1482 | - * @return int |
|
1483 | - */ |
|
1484 | - public function increase_usage( $by = 1 ) { |
|
1485 | - |
|
1486 | - // Abort if zero. |
|
1487 | - if ( empty( $by ) ) { |
|
1488 | - return; |
|
1489 | - } |
|
1490 | - |
|
1491 | - // Increase the usage. |
|
1492 | - $this->set_uses( $this->get_uses() + (int) $by ); |
|
1493 | - |
|
1494 | - // Save the discount. |
|
1495 | - $this->save(); |
|
1496 | - |
|
1497 | - // Fire relevant hooks. |
|
1498 | - if ( (int) $by > 0 ) { |
|
1499 | - do_action( 'wpinv_discount_increase_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1500 | - } else { |
|
1501 | - do_action( 'wpinv_discount_decrease_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1502 | - } |
|
1503 | - |
|
1504 | - // Return the number of times the discount has been used. |
|
1505 | - return $this->get_uses(); |
|
1506 | - } |
|
1507 | - |
|
1508 | - /** |
|
1509 | - * Alias of self::__toString() |
|
1510 | - * |
|
1511 | - * @since 1.0.15 |
|
1512 | - * @return string|false |
|
1513 | - */ |
|
1514 | - public function get_data_as_json() { |
|
1515 | - return $this->__toString(); |
|
1516 | - } |
|
1517 | - |
|
1518 | - /** |
|
1519 | - * Returns a discount's discounted amount. |
|
1520 | - * |
|
1521 | - * @since 1.0.15 |
|
1522 | - * @param float $amount |
|
1523 | - * @return float |
|
1524 | - */ |
|
1525 | - public function get_discounted_amount( $amount ) { |
|
1526 | - |
|
1527 | - // Convert amount to float. |
|
1528 | - $amount = (float) $amount; |
|
1529 | - |
|
1530 | - // Get discount amount. |
|
1531 | - $discount_amount = $this->get_amount(); |
|
1532 | - |
|
1533 | - if ( empty( $discount_amount ) ) { |
|
1534 | - return 0; |
|
1535 | - } |
|
1536 | - |
|
1537 | - // Format the amount. |
|
1538 | - $discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) ); |
|
1539 | - |
|
1540 | - // If this is a percentage discount. |
|
1541 | - if ( $this->is_type( 'percent' ) ) { |
|
1464 | + return true; |
|
1465 | + } |
|
1466 | + |
|
1467 | + /** |
|
1468 | + * Deletes the discount from the database |
|
1469 | + * |
|
1470 | + * @since 1.0.15 |
|
1471 | + * @return boolean |
|
1472 | + */ |
|
1473 | + public function remove() { |
|
1474 | + return $this->delete(); |
|
1475 | + } |
|
1476 | + |
|
1477 | + /** |
|
1478 | + * Increases a discount's usage. |
|
1479 | + * |
|
1480 | + * @since 1.0.15 |
|
1481 | + * @param int $by The number of usages to increas by. |
|
1482 | + * @return int |
|
1483 | + */ |
|
1484 | + public function increase_usage( $by = 1 ) { |
|
1485 | + |
|
1486 | + // Abort if zero. |
|
1487 | + if ( empty( $by ) ) { |
|
1488 | + return; |
|
1489 | + } |
|
1490 | + |
|
1491 | + // Increase the usage. |
|
1492 | + $this->set_uses( $this->get_uses() + (int) $by ); |
|
1493 | + |
|
1494 | + // Save the discount. |
|
1495 | + $this->save(); |
|
1496 | + |
|
1497 | + // Fire relevant hooks. |
|
1498 | + if ( (int) $by > 0 ) { |
|
1499 | + do_action( 'wpinv_discount_increase_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1500 | + } else { |
|
1501 | + do_action( 'wpinv_discount_decrease_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1502 | + } |
|
1503 | + |
|
1504 | + // Return the number of times the discount has been used. |
|
1505 | + return $this->get_uses(); |
|
1506 | + } |
|
1507 | + |
|
1508 | + /** |
|
1509 | + * Alias of self::__toString() |
|
1510 | + * |
|
1511 | + * @since 1.0.15 |
|
1512 | + * @return string|false |
|
1513 | + */ |
|
1514 | + public function get_data_as_json() { |
|
1515 | + return $this->__toString(); |
|
1516 | + } |
|
1517 | + |
|
1518 | + /** |
|
1519 | + * Returns a discount's discounted amount. |
|
1520 | + * |
|
1521 | + * @since 1.0.15 |
|
1522 | + * @param float $amount |
|
1523 | + * @return float |
|
1524 | + */ |
|
1525 | + public function get_discounted_amount( $amount ) { |
|
1526 | + |
|
1527 | + // Convert amount to float. |
|
1528 | + $amount = (float) $amount; |
|
1529 | + |
|
1530 | + // Get discount amount. |
|
1531 | + $discount_amount = $this->get_amount(); |
|
1532 | + |
|
1533 | + if ( empty( $discount_amount ) ) { |
|
1534 | + return 0; |
|
1535 | + } |
|
1536 | + |
|
1537 | + // Format the amount. |
|
1538 | + $discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) ); |
|
1539 | + |
|
1540 | + // If this is a percentage discount. |
|
1541 | + if ( $this->is_type( 'percent' ) ) { |
|
1542 | 1542 | $discount_amount = $amount * ( $discount_amount / 100 ); |
1543 | - } |
|
1543 | + } |
|
1544 | 1544 | |
1545 | - // Discount can not be less than zero... |
|
1546 | - if ( $discount_amount < 0 ) { |
|
1547 | - $discount_amount = 0; |
|
1548 | - } |
|
1545 | + // Discount can not be less than zero... |
|
1546 | + if ( $discount_amount < 0 ) { |
|
1547 | + $discount_amount = 0; |
|
1548 | + } |
|
1549 | 1549 | |
1550 | - // ... or more than the amount. |
|
1551 | - if ( $discount_amount > $amount ) { |
|
1552 | - $discount_amount = $amount; |
|
1553 | - } |
|
1550 | + // ... or more than the amount. |
|
1551 | + if ( $discount_amount > $amount ) { |
|
1552 | + $discount_amount = $amount; |
|
1553 | + } |
|
1554 | 1554 | |
1555 | - return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this ); |
|
1556 | - } |
|
1555 | + return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this ); |
|
1556 | + } |
|
1557 | 1557 | |
1558 | 1558 | } |
@@ -775,10 +775,10 @@ discard block |
||
775 | 775 | $allowed_fee_keys = apply_filters( |
776 | 776 | 'wpinv_fee_keys', |
777 | 777 | array( |
778 | - 'index', |
|
779 | - 'label', |
|
780 | - 'amount', |
|
781 | - 'type', |
|
778 | + 'index', |
|
779 | + 'label', |
|
780 | + 'amount', |
|
781 | + 'type', |
|
782 | 782 | ) |
783 | 783 | ); |
784 | 784 | |
@@ -850,19 +850,19 @@ discard block |
||
850 | 850 | $note_id = wp_insert_comment( |
851 | 851 | wp_filter_comment( |
852 | 852 | array( |
853 | - 'comment_post_ID' => $this->ID, |
|
854 | - 'comment_content' => $note, |
|
855 | - 'comment_agent' => 'WPInvoicing', |
|
856 | - 'user_id' => is_admin() ? get_current_user_id() : 0, |
|
857 | - 'comment_date' => current_time( 'mysql' ), |
|
858 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
859 | - 'comment_approved' => 1, |
|
860 | - 'comment_parent' => 0, |
|
861 | - 'comment_author' => $comment_author, |
|
862 | - 'comment_author_IP' => wpinv_get_ip(), |
|
863 | - 'comment_author_url' => '', |
|
864 | - 'comment_author_email' => $comment_author_email, |
|
865 | - 'comment_type' => 'wpinv_note', |
|
853 | + 'comment_post_ID' => $this->ID, |
|
854 | + 'comment_content' => $note, |
|
855 | + 'comment_agent' => 'WPInvoicing', |
|
856 | + 'user_id' => is_admin() ? get_current_user_id() : 0, |
|
857 | + 'comment_date' => current_time( 'mysql' ), |
|
858 | + 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
859 | + 'comment_approved' => 1, |
|
860 | + 'comment_parent' => 0, |
|
861 | + 'comment_author' => $comment_author, |
|
862 | + 'comment_author_IP' => wpinv_get_ip(), |
|
863 | + 'comment_author_url' => '', |
|
864 | + 'comment_author_email' => $comment_author_email, |
|
865 | + 'comment_type' => 'wpinv_note', |
|
866 | 866 | ) |
867 | 867 | ) |
868 | 868 | ); |
@@ -875,8 +875,8 @@ discard block |
||
875 | 875 | do_action( |
876 | 876 | 'wpinv_new_customer_note', |
877 | 877 | array( |
878 | - 'invoice_id' => $this->ID, |
|
879 | - 'user_note' => $note, |
|
878 | + 'invoice_id' => $this->ID, |
|
879 | + 'user_note' => $note, |
|
880 | 880 | ) |
881 | 881 | ); |
882 | 882 | } |
@@ -13,42 +13,42 @@ |
||
13 | 13 | |
14 | 14 | foreach ( array_keys( $widget->get_subscriptions_table_columns() ) as $column ) : |
15 | 15 | |
16 | - $class = sanitize_html_class( $column ); |
|
17 | - echo "<td class='getpaid-subscriptions-table-column-" . esc_attr( $class ) . "'>"; |
|
16 | + $class = sanitize_html_class( $column ); |
|
17 | + echo "<td class='getpaid-subscriptions-table-column-" . esc_attr( $class ) . "'>"; |
|
18 | 18 | |
19 | - do_action( "getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription ); |
|
19 | + do_action( "getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription ); |
|
20 | 20 | |
21 | - switch ( $column ) : |
|
21 | + switch ( $column ) : |
|
22 | 22 | |
23 | - case 'subscription': |
|
24 | - $subscription_id = (int) $subscription->get_id(); |
|
25 | - $url = esc_url( $subscription->get_view_url() ); |
|
26 | - $id_label = sprintf( |
|
27 | - esc_attr_x( '#%s', 'subscription id', 'invoicing' ), |
|
28 | - (int) $subscription->get_id() |
|
29 | - ); |
|
30 | - echo wp_kses_post( $widget->add_row_actions( "<a href='$url' class='font-weight-bold text-decoration-none'>$id_label</a>", $subscription ) ); |
|
31 | - break; |
|
23 | + case 'subscription': |
|
24 | + $subscription_id = (int) $subscription->get_id(); |
|
25 | + $url = esc_url( $subscription->get_view_url() ); |
|
26 | + $id_label = sprintf( |
|
27 | + esc_attr_x( '#%s', 'subscription id', 'invoicing' ), |
|
28 | + (int) $subscription->get_id() |
|
29 | + ); |
|
30 | + echo wp_kses_post( $widget->add_row_actions( "<a href='$url' class='font-weight-bold text-decoration-none'>$id_label</a>", $subscription ) ); |
|
31 | + break; |
|
32 | 32 | |
33 | - case 'status': |
|
34 | - echo esc_html( $subscription->get_status_label() ); |
|
35 | - break; |
|
33 | + case 'status': |
|
34 | + echo esc_html( $subscription->get_status_label() ); |
|
35 | + break; |
|
36 | 36 | |
37 | - case 'renewal-date': |
|
38 | - $renewal = getpaid_format_date_value( $subscription->get_next_renewal_date() ); |
|
39 | - echo $subscription->is_active() ? esc_html( $renewal ) : '—'; |
|
40 | - break; |
|
37 | + case 'renewal-date': |
|
38 | + $renewal = getpaid_format_date_value( $subscription->get_next_renewal_date() ); |
|
39 | + echo $subscription->is_active() ? esc_html( $renewal ) : '—'; |
|
40 | + break; |
|
41 | 41 | |
42 | - case 'amount': |
|
43 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
44 | - $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
45 | - echo wp_kses_post( "<span>$amount</span> / <span class='getpaid-item-recurring-period'>$frequency</span>" ); |
|
46 | - break; |
|
42 | + case 'amount': |
|
43 | + $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
44 | + $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
45 | + echo wp_kses_post( "<span>$amount</span> / <span class='getpaid-item-recurring-period'>$frequency</span>" ); |
|
46 | + break; |
|
47 | 47 | |
48 | - endswitch; |
|
48 | + endswitch; |
|
49 | 49 | |
50 | - do_action( "getpaid_subscriptions_frontend_subscription_table_$column", $subscription ); |
|
50 | + do_action( "getpaid_subscriptions_frontend_subscription_table_$column", $subscription ); |
|
51 | 51 | |
52 | - echo '</td>'; |
|
52 | + echo '</td>'; |
|
53 | 53 | |
54 | 54 | endforeach; |
@@ -25,7 +25,7 @@ |
||
25 | 25 | <?php |
26 | 26 | $img = wpinv_get_option( 'email_header_image', '' ); |
27 | 27 | if ( $img ) { |
28 | - echo '<p style="margin-top:0;"><img style="max-width:100%" src="' . esc_url( $img ) . '" alt="' . esc_attr( wpinv_get_blogname() ) . '" /></p>'; |
|
28 | + echo '<p style="margin-top:0;"><img style="max-width:100%" src="' . esc_url( $img ) . '" alt="' . esc_attr( wpinv_get_blogname() ) . '" /></p>'; |
|
29 | 29 | } |
30 | 30 | ?> |
31 | 31 | </div> |
@@ -21,101 +21,101 @@ |
||
21 | 21 | global $wp_settings_fields; |
22 | 22 | |
23 | 23 | if ( isset( $wp_settings_fields[ $page ][ $section ] ) ) { |
24 | - $settings = $wp_settings_fields[ $page ][ $section ]; |
|
25 | - |
|
26 | - foreach ( $settings as $field ) { |
|
27 | - |
|
28 | - $name = esc_attr( $field['id'] ); |
|
29 | - $id = sanitize_key( $name ); |
|
30 | - $class = ''; |
|
31 | - $value = isset( $field['args']['std'] ) ? $field['args']['std'] : ''; |
|
32 | - $value = wpinv_clean( wpinv_get_option( $field['args']['id'], $value ) ); |
|
33 | - $help_text = isset( $field['args']['desc'] ) ? wp_kses_post( $field['args']['desc'] ) : ''; |
|
34 | - $type = str_replace( 'wpinv_', '', str_replace( '_callback', '', $field['callback'] ) ); |
|
35 | - $label = isset( $field['args']['name'] ) ? wp_kses_post( $field['args']['name'] ) : ''; |
|
36 | - $options = isset( $field['args']['options'] ) ? $field['args']['options'] : array(); |
|
37 | - |
|
38 | - if ( false !== strpos( $name, 'logo' ) ) { |
|
39 | - $type = 'hidden'; |
|
24 | + $settings = $wp_settings_fields[ $page ][ $section ]; |
|
25 | + |
|
26 | + foreach ( $settings as $field ) { |
|
27 | + |
|
28 | + $name = esc_attr( $field['id'] ); |
|
29 | + $id = sanitize_key( $name ); |
|
30 | + $class = ''; |
|
31 | + $value = isset( $field['args']['std'] ) ? $field['args']['std'] : ''; |
|
32 | + $value = wpinv_clean( wpinv_get_option( $field['args']['id'], $value ) ); |
|
33 | + $help_text = isset( $field['args']['desc'] ) ? wp_kses_post( $field['args']['desc'] ) : ''; |
|
34 | + $type = str_replace( 'wpinv_', '', str_replace( '_callback', '', $field['callback'] ) ); |
|
35 | + $label = isset( $field['args']['name'] ) ? wp_kses_post( $field['args']['name'] ) : ''; |
|
36 | + $options = isset( $field['args']['options'] ) ? $field['args']['options'] : array(); |
|
37 | + |
|
38 | + if ( false !== strpos( $name, 'logo' ) ) { |
|
39 | + $type = 'hidden'; |
|
40 | 40 | } |
41 | 41 | |
42 | - if ( 'country_states' == $type ) { |
|
42 | + if ( 'country_states' == $type ) { |
|
43 | 43 | |
44 | - if ( 0 == count( wpinv_get_country_states( wpinv_get_default_country() ) ) ) { |
|
45 | - $type = 'text'; |
|
44 | + if ( 0 == count( wpinv_get_country_states( wpinv_get_default_country() ) ) ) { |
|
45 | + $type = 'text'; |
|
46 | 46 | } else { |
47 | - $type = 'select'; |
|
47 | + $type = 'select'; |
|
48 | 48 | } |
49 | 49 | |
50 | - $class = 'getpaid_js_field-state'; |
|
50 | + $class = 'getpaid_js_field-state'; |
|
51 | 51 | } |
52 | 52 | |
53 | - if ( 'wpinv_settings[default_country]' == $name ) { |
|
54 | - $class = 'getpaid_js_field-country'; |
|
53 | + if ( 'wpinv_settings[default_country]' == $name ) { |
|
54 | + $class = 'getpaid_js_field-country'; |
|
55 | 55 | } |
56 | 56 | |
57 | - switch ( $type ) { |
|
57 | + switch ( $type ) { |
|
58 | 58 | |
59 | - case 'hidden': |
|
60 | - echo "<input type='hidden' id='" . esc_attr( $id ) . "' name='" . esc_attr( $name ) . "' value='" . esc_attr( $value ) . "' />"; |
|
61 | - break; |
|
62 | - case 'text': |
|
59 | + case 'hidden': |
|
60 | + echo "<input type='hidden' id='" . esc_attr( $id ) . "' name='" . esc_attr( $name ) . "' value='" . esc_attr( $value ) . "' />"; |
|
61 | + break; |
|
62 | + case 'text': |
|
63 | 63 | case 'number': |
64 | - aui()->input( |
|
64 | + aui()->input( |
|
65 | 65 | array( |
66 | - 'type' => $type, |
|
67 | - 'id' => $id, |
|
68 | - 'name' => $name, |
|
69 | - 'value' => is_scalar( $value ) ? esc_attr( $value ) : '', |
|
70 | - 'required' => false, |
|
71 | - 'help_text' => $help_text, |
|
72 | - 'label' => $label, |
|
73 | - 'class' => $class, |
|
74 | - 'label_type' => 'floating', |
|
75 | - 'label_class' => 'settings-label', |
|
66 | + 'type' => $type, |
|
67 | + 'id' => $id, |
|
68 | + 'name' => $name, |
|
69 | + 'value' => is_scalar( $value ) ? esc_attr( $value ) : '', |
|
70 | + 'required' => false, |
|
71 | + 'help_text' => $help_text, |
|
72 | + 'label' => $label, |
|
73 | + 'class' => $class, |
|
74 | + 'label_type' => 'floating', |
|
75 | + 'label_class' => 'settings-label', |
|
76 | 76 | ), |
77 | - true |
|
77 | + true |
|
78 | 78 | ); |
79 | - break; |
|
80 | - case 'textarea': |
|
81 | - aui()->textarea( |
|
82 | - array( |
|
83 | - 'id' => $id, |
|
84 | - 'name' => $name, |
|
85 | - 'value' => is_scalar( $value ) ? esc_textarea( $value ) : '', |
|
86 | - 'required' => false, |
|
87 | - 'help_text' => $help_text, |
|
88 | - 'label' => $label, |
|
89 | - 'rows' => '4', |
|
90 | - 'class' => $class, |
|
91 | - 'label_type' => 'floating', |
|
92 | - 'label_class' => 'settings-label', |
|
93 | - ), |
|
94 | - true |
|
95 | - ); |
|
96 | - |
|
97 | - break; |
|
98 | - case 'select': |
|
99 | - aui()->select( |
|
100 | - array( |
|
101 | - 'id' => $id, |
|
102 | - 'name' => $name, |
|
103 | - 'placeholder' => '', |
|
104 | - 'value' => is_scalar( $value ) ? esc_attr( $value ) : '', |
|
105 | - 'required' => false, |
|
106 | - 'help_text' => $help_text, |
|
107 | - 'label' => $label, |
|
108 | - 'options' => $options, |
|
109 | - 'label_type' => 'floating', |
|
110 | - 'label_class' => 'settings-label', |
|
111 | - 'class' => $class, |
|
112 | - ), |
|
113 | - true |
|
114 | - ); |
|
115 | - break; |
|
116 | - default: |
|
117 | - // Do something. |
|
118 | - break; |
|
79 | + break; |
|
80 | + case 'textarea': |
|
81 | + aui()->textarea( |
|
82 | + array( |
|
83 | + 'id' => $id, |
|
84 | + 'name' => $name, |
|
85 | + 'value' => is_scalar( $value ) ? esc_textarea( $value ) : '', |
|
86 | + 'required' => false, |
|
87 | + 'help_text' => $help_text, |
|
88 | + 'label' => $label, |
|
89 | + 'rows' => '4', |
|
90 | + 'class' => $class, |
|
91 | + 'label_type' => 'floating', |
|
92 | + 'label_class' => 'settings-label', |
|
93 | + ), |
|
94 | + true |
|
95 | + ); |
|
96 | + |
|
97 | + break; |
|
98 | + case 'select': |
|
99 | + aui()->select( |
|
100 | + array( |
|
101 | + 'id' => $id, |
|
102 | + 'name' => $name, |
|
103 | + 'placeholder' => '', |
|
104 | + 'value' => is_scalar( $value ) ? esc_attr( $value ) : '', |
|
105 | + 'required' => false, |
|
106 | + 'help_text' => $help_text, |
|
107 | + 'label' => $label, |
|
108 | + 'options' => $options, |
|
109 | + 'label_type' => 'floating', |
|
110 | + 'label_class' => 'settings-label', |
|
111 | + 'class' => $class, |
|
112 | + ), |
|
113 | + true |
|
114 | + ); |
|
115 | + break; |
|
116 | + default: |
|
117 | + // Do something. |
|
118 | + break; |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | } |
@@ -17,395 +17,395 @@ |
||
17 | 17 | */ |
18 | 18 | class GetPaid_Admin_Setup_Wizard { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string Current Step |
|
22 | - */ |
|
23 | - protected $step = ''; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string|false Previous Step |
|
27 | - */ |
|
28 | - protected $previous_step = ''; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string|false Next Step |
|
32 | - */ |
|
33 | - protected $next_step = ''; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array All available steps for the setup wizard |
|
37 | - */ |
|
38 | - protected $steps = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * Class constructor. |
|
42 | - * |
|
43 | - * @since 2.4.0 |
|
44 | - */ |
|
45 | - public function __construct() { |
|
46 | - |
|
47 | - if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | - add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | - add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | - } |
|
51 | - |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Add admin menus/screens. |
|
56 | - * |
|
57 | - * @since 2.4.0 |
|
58 | - */ |
|
59 | - public function add_menu() { |
|
60 | - add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Sets up the setup wizard. |
|
65 | - * |
|
66 | - * @since 2.4.0 |
|
67 | - */ |
|
68 | - public function setup_wizard() { |
|
69 | - |
|
70 | - if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
71 | - $this->setup_globals(); |
|
72 | - $this->maybe_save_current_step(); |
|
73 | - $this->display_wizard(); |
|
74 | - exit; |
|
75 | - } |
|
76 | - |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Sets up class variables. |
|
81 | - * |
|
82 | - * @since 2.4.0 |
|
83 | - */ |
|
84 | - protected function setup_globals() { |
|
85 | - $this->steps = $this->get_setup_steps(); |
|
86 | - $this->step = $this->get_current_step(); |
|
87 | - $this->previous_step = $this->get_previous_step(); |
|
88 | - $this->next_step = $this->get_next_step(); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Saves the current step. |
|
93 | - * |
|
94 | - * @since 2.4.0 |
|
95 | - */ |
|
96 | - protected function maybe_save_current_step() { |
|
97 | - if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
98 | - call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Returns the setup steps. |
|
104 | - * |
|
105 | - * @since 2.4.0 |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - protected function get_setup_steps() { |
|
109 | - |
|
110 | - $steps = array( |
|
111 | - |
|
112 | - 'introduction' => array( |
|
113 | - 'name' => __( 'Introduction', 'invoicing' ), |
|
114 | - 'view' => array( $this, 'setup_introduction' ), |
|
115 | - 'handler' => '', |
|
116 | - ), |
|
117 | - |
|
118 | - 'business_details' => array( |
|
119 | - 'name' => __( 'Business Details', 'invoicing' ), |
|
120 | - 'view' => array( $this, 'setup_business' ), |
|
121 | - 'handler' => '', |
|
122 | - ), |
|
123 | - |
|
124 | - 'currency' => array( |
|
125 | - 'name' => __( 'Currency', 'invoicing' ), |
|
126 | - 'view' => array( $this, 'setup_currency' ), |
|
127 | - 'handler' => '', |
|
128 | - ), |
|
129 | - |
|
130 | - 'payments' => array( |
|
131 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
132 | - 'view' => array( $this, 'setup_payments' ), |
|
133 | - 'handler' => array( $this, 'setup_payments_save' ), |
|
134 | - ), |
|
135 | - |
|
136 | - 'recommend' => array( |
|
137 | - 'name' => __( 'Recommend', 'invoicing' ), |
|
138 | - 'view' => array( $this, 'setup_recommend' ), |
|
139 | - 'handler' => '', |
|
140 | - ), |
|
141 | - |
|
142 | - 'next_steps' => array( |
|
143 | - 'name' => __( 'Get Paid', 'invoicing' ), |
|
144 | - 'view' => array( $this, 'setup_ready' ), |
|
145 | - 'handler' => '', |
|
146 | - ), |
|
147 | - |
|
148 | - ); |
|
149 | - |
|
150 | - return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
151 | - |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns the current step. |
|
156 | - * |
|
157 | - * @since 2.4.0 |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - protected function get_current_step() { |
|
161 | - $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
162 | - return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Returns the previous step. |
|
167 | - * |
|
168 | - * @since 2.4.0 |
|
169 | - * @return string|false |
|
170 | - */ |
|
171 | - protected function get_previous_step() { |
|
172 | - |
|
173 | - $previous = false; |
|
174 | - $current = $this->step; |
|
175 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
176 | - if ( $current === $step ) { |
|
177 | - return $previous; |
|
178 | - } |
|
179 | - |
|
180 | - $previous = $step; |
|
181 | - } |
|
182 | - |
|
183 | - return false; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Returns the next step. |
|
188 | - * |
|
189 | - * @since 2.4.0 |
|
190 | - * @return string|false |
|
191 | - */ |
|
192 | - protected function get_next_step() { |
|
193 | - |
|
194 | - $on_current = false; |
|
195 | - $current = $this->step; |
|
196 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
197 | - |
|
198 | - if ( $on_current ) { |
|
199 | - return $step; |
|
200 | - } |
|
201 | - |
|
202 | - if ( $current === $step ) { |
|
203 | - return $on_current = true; |
|
204 | - } |
|
20 | + /** |
|
21 | + * @var string Current Step |
|
22 | + */ |
|
23 | + protected $step = ''; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string|false Previous Step |
|
27 | + */ |
|
28 | + protected $previous_step = ''; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string|false Next Step |
|
32 | + */ |
|
33 | + protected $next_step = ''; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array All available steps for the setup wizard |
|
37 | + */ |
|
38 | + protected $steps = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * Class constructor. |
|
42 | + * |
|
43 | + * @since 2.4.0 |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | + |
|
47 | + if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | + add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | + add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | + } |
|
51 | + |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Add admin menus/screens. |
|
56 | + * |
|
57 | + * @since 2.4.0 |
|
58 | + */ |
|
59 | + public function add_menu() { |
|
60 | + add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Sets up the setup wizard. |
|
65 | + * |
|
66 | + * @since 2.4.0 |
|
67 | + */ |
|
68 | + public function setup_wizard() { |
|
69 | + |
|
70 | + if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
71 | + $this->setup_globals(); |
|
72 | + $this->maybe_save_current_step(); |
|
73 | + $this->display_wizard(); |
|
74 | + exit; |
|
75 | + } |
|
76 | + |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Sets up class variables. |
|
81 | + * |
|
82 | + * @since 2.4.0 |
|
83 | + */ |
|
84 | + protected function setup_globals() { |
|
85 | + $this->steps = $this->get_setup_steps(); |
|
86 | + $this->step = $this->get_current_step(); |
|
87 | + $this->previous_step = $this->get_previous_step(); |
|
88 | + $this->next_step = $this->get_next_step(); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Saves the current step. |
|
93 | + * |
|
94 | + * @since 2.4.0 |
|
95 | + */ |
|
96 | + protected function maybe_save_current_step() { |
|
97 | + if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
98 | + call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Returns the setup steps. |
|
104 | + * |
|
105 | + * @since 2.4.0 |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + protected function get_setup_steps() { |
|
109 | + |
|
110 | + $steps = array( |
|
111 | + |
|
112 | + 'introduction' => array( |
|
113 | + 'name' => __( 'Introduction', 'invoicing' ), |
|
114 | + 'view' => array( $this, 'setup_introduction' ), |
|
115 | + 'handler' => '', |
|
116 | + ), |
|
117 | + |
|
118 | + 'business_details' => array( |
|
119 | + 'name' => __( 'Business Details', 'invoicing' ), |
|
120 | + 'view' => array( $this, 'setup_business' ), |
|
121 | + 'handler' => '', |
|
122 | + ), |
|
123 | + |
|
124 | + 'currency' => array( |
|
125 | + 'name' => __( 'Currency', 'invoicing' ), |
|
126 | + 'view' => array( $this, 'setup_currency' ), |
|
127 | + 'handler' => '', |
|
128 | + ), |
|
129 | + |
|
130 | + 'payments' => array( |
|
131 | + 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
132 | + 'view' => array( $this, 'setup_payments' ), |
|
133 | + 'handler' => array( $this, 'setup_payments_save' ), |
|
134 | + ), |
|
135 | + |
|
136 | + 'recommend' => array( |
|
137 | + 'name' => __( 'Recommend', 'invoicing' ), |
|
138 | + 'view' => array( $this, 'setup_recommend' ), |
|
139 | + 'handler' => '', |
|
140 | + ), |
|
141 | + |
|
142 | + 'next_steps' => array( |
|
143 | + 'name' => __( 'Get Paid', 'invoicing' ), |
|
144 | + 'view' => array( $this, 'setup_ready' ), |
|
145 | + 'handler' => '', |
|
146 | + ), |
|
147 | + |
|
148 | + ); |
|
149 | + |
|
150 | + return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
151 | + |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns the current step. |
|
156 | + * |
|
157 | + * @since 2.4.0 |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + protected function get_current_step() { |
|
161 | + $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
162 | + return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Returns the previous step. |
|
167 | + * |
|
168 | + * @since 2.4.0 |
|
169 | + * @return string|false |
|
170 | + */ |
|
171 | + protected function get_previous_step() { |
|
172 | + |
|
173 | + $previous = false; |
|
174 | + $current = $this->step; |
|
175 | + foreach ( array_keys( $this->steps ) as $step ) { |
|
176 | + if ( $current === $step ) { |
|
177 | + return $previous; |
|
178 | + } |
|
179 | + |
|
180 | + $previous = $step; |
|
181 | + } |
|
182 | + |
|
183 | + return false; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Returns the next step. |
|
188 | + * |
|
189 | + * @since 2.4.0 |
|
190 | + * @return string|false |
|
191 | + */ |
|
192 | + protected function get_next_step() { |
|
193 | + |
|
194 | + $on_current = false; |
|
195 | + $current = $this->step; |
|
196 | + foreach ( array_keys( $this->steps ) as $step ) { |
|
197 | + |
|
198 | + if ( $on_current ) { |
|
199 | + return $step; |
|
200 | + } |
|
201 | + |
|
202 | + if ( $current === $step ) { |
|
203 | + return $on_current = true; |
|
204 | + } |
|
205 | 205 | } |
206 | 206 | |
207 | - return false; |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Displays the setup wizard. |
|
212 | - * |
|
213 | - * @since 2.4.0 |
|
214 | - */ |
|
215 | - public function display_wizard() { |
|
216 | - $this->display_header(); |
|
217 | - $this->display_current_step(); |
|
218 | - $this->display_footer(); |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Displays the Wizard Header. |
|
223 | - * |
|
224 | - * @since 2.0.0 |
|
225 | - */ |
|
226 | - public function display_header() { |
|
227 | - $steps = $this->steps; |
|
228 | - $current = $this->step; |
|
229 | - $next_step = $this->next_step; |
|
230 | - array_shift( $steps ); |
|
231 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Displays the content for the current step. |
|
236 | - * |
|
237 | - * @since 2.4.0 |
|
238 | - */ |
|
239 | - public function display_current_step() { |
|
240 | - ?> |
|
207 | + return false; |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Displays the setup wizard. |
|
212 | + * |
|
213 | + * @since 2.4.0 |
|
214 | + */ |
|
215 | + public function display_wizard() { |
|
216 | + $this->display_header(); |
|
217 | + $this->display_current_step(); |
|
218 | + $this->display_footer(); |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Displays the Wizard Header. |
|
223 | + * |
|
224 | + * @since 2.0.0 |
|
225 | + */ |
|
226 | + public function display_header() { |
|
227 | + $steps = $this->steps; |
|
228 | + $current = $this->step; |
|
229 | + $next_step = $this->next_step; |
|
230 | + array_shift( $steps ); |
|
231 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Displays the content for the current step. |
|
236 | + * |
|
237 | + * @since 2.4.0 |
|
238 | + */ |
|
239 | + public function display_current_step() { |
|
240 | + ?> |
|
241 | 241 | <div class="gp-setup-content rowx mw-100 text-center mb-3"> |
242 | 242 | <div class="col-12 col-md-5 m-auto"> |
243 | 243 | <?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?> |
244 | 244 | </div> |
245 | 245 | </div> |
246 | 246 | <?php |
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Setup Wizard Footer. |
|
251 | - * |
|
252 | - * @since 2.4.0 |
|
253 | - */ |
|
254 | - public function display_footer() { |
|
255 | - |
|
256 | - if ( isset( $_GET['step'] ) ) { |
|
257 | - $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
258 | - |
|
259 | - echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . esc_url( $this->get_next_step_link() ) . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . esc_html( $label ) . '</a></p>'; |
|
260 | - } |
|
261 | - |
|
262 | - echo '</body></html>'; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Introduction step. |
|
267 | - * |
|
268 | - * @since 2.0.0 |
|
269 | - */ |
|
270 | - public function setup_introduction() { |
|
271 | - $next_url = $this->get_next_step_link(); |
|
272 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Get the URL for the next step's screen. |
|
277 | - * |
|
278 | - * @param string step slug (default: current step) |
|
279 | - * |
|
280 | - * @return string URL for next step if a next step exists. |
|
281 | - * Admin URL if it's the last step. |
|
282 | - * Empty string on failure. |
|
283 | - * @since 3.0.0 |
|
284 | - */ |
|
285 | - public function get_next_step_link( $step = '' ) { |
|
286 | - if ( ! $step ) { |
|
287 | - $step = $this->step; |
|
288 | - } |
|
289 | - |
|
290 | - $keys = array_keys( $this->steps ); |
|
291 | - if ( end( $keys ) === $step ) { |
|
292 | - return admin_url(); |
|
293 | - } |
|
294 | - |
|
295 | - $step_index = array_search( $step, $keys ); |
|
296 | - if ( false === $step_index ) { |
|
297 | - return ''; |
|
298 | - } |
|
299 | - |
|
300 | - return remove_query_arg( 'settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ) ); |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Setup maps api. |
|
305 | - * |
|
306 | - * @since 2.0.0 |
|
307 | - */ |
|
308 | - public function setup_business() { |
|
309 | - $next_url = $this->get_next_step_link(); |
|
310 | - $wizard = $this; |
|
311 | - $page = 'wpinv_settings_general_main'; |
|
312 | - $section = 'wpinv_settings_general_main'; |
|
313 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Default Location settings. |
|
318 | - * |
|
319 | - * @since 2.0.0 |
|
320 | - */ |
|
321 | - public function setup_currency() { |
|
322 | - $next_url = $this->get_next_step_link(); |
|
323 | - $wizard = $this; |
|
324 | - $page = 'wpinv_settings_general_currency_section'; |
|
325 | - $section = 'wpinv_settings_general_currency_section'; |
|
326 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * Installation of recommended plugins. |
|
331 | - * |
|
332 | - * @since 1.0.0 |
|
333 | - */ |
|
334 | - public function setup_recommend() { |
|
335 | - $next_url = $this->get_next_step_link(); |
|
336 | - $recommended_plugins = self::get_recommend_wp_plugins(); |
|
337 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * A list of recommended wp.org plugins. |
|
342 | - * @return array |
|
343 | - */ |
|
344 | - public static function get_recommend_wp_plugins() { |
|
345 | - return array( |
|
346 | - 'ayecode-connect' => array( |
|
347 | - 'file' => 'ayecode-connect/ayecode-connect.php', |
|
348 | - 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
|
349 | - 'slug' => 'ayecode-connect', |
|
350 | - 'name' => 'AyeCode Connect', |
|
351 | - 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'invoicing' ), |
|
352 | - ), |
|
353 | - 'invoicing-quotes' => array( |
|
354 | - 'file' => 'invoicing-quotes/wpinv-quote.php', |
|
355 | - 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
|
356 | - 'slug' => 'invoicing-quotes', |
|
357 | - 'name' => 'Customer Quotes', |
|
358 | - 'desc' => __( 'Create & Send Quotes to Customers and have them accept and pay.', 'invoicing' ), |
|
359 | - ), |
|
360 | - 'userswp' => array( |
|
361 | - 'file' => 'userswp/userswp.php', |
|
362 | - 'url' => 'https://wordpress.org/plugins/userswp/', |
|
363 | - 'slug' => 'userswp', |
|
364 | - 'name' => 'UsersWP', |
|
365 | - 'desc' => __( 'Frontend user login and registration as well as slick profile pages.', 'invoicing' ), |
|
366 | - ), |
|
367 | - ); |
|
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * Dummy Data setup. |
|
372 | - * |
|
373 | - * @since 2.4.0 |
|
374 | - */ |
|
375 | - public function setup_payments() { |
|
376 | - $next_url = $this->get_next_step_link(); |
|
377 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Dummy data save. |
|
382 | - * |
|
383 | - * This is done via ajax so we just pass onto the next step. |
|
384 | - * |
|
385 | - * @since 2.0.0 |
|
386 | - */ |
|
387 | - public function setup_payments_save() { |
|
388 | - check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
389 | - wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
390 | - |
|
391 | - if ( ! empty( $_POST['paypal-email'] ) ) { |
|
392 | - wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
393 | - wpinv_update_option( 'paypal_active', 1 ); |
|
394 | - wpinv_update_option( 'paypal_sandbox', 0 ); |
|
395 | - } |
|
396 | - |
|
397 | - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
398 | - exit; |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * Final step. |
|
403 | - * |
|
404 | - * @since 2.0.0 |
|
405 | - */ |
|
406 | - public function setup_ready() { |
|
407 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
408 | - } |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Setup Wizard Footer. |
|
251 | + * |
|
252 | + * @since 2.4.0 |
|
253 | + */ |
|
254 | + public function display_footer() { |
|
255 | + |
|
256 | + if ( isset( $_GET['step'] ) ) { |
|
257 | + $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
258 | + |
|
259 | + echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . esc_url( $this->get_next_step_link() ) . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . esc_html( $label ) . '</a></p>'; |
|
260 | + } |
|
261 | + |
|
262 | + echo '</body></html>'; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Introduction step. |
|
267 | + * |
|
268 | + * @since 2.0.0 |
|
269 | + */ |
|
270 | + public function setup_introduction() { |
|
271 | + $next_url = $this->get_next_step_link(); |
|
272 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Get the URL for the next step's screen. |
|
277 | + * |
|
278 | + * @param string step slug (default: current step) |
|
279 | + * |
|
280 | + * @return string URL for next step if a next step exists. |
|
281 | + * Admin URL if it's the last step. |
|
282 | + * Empty string on failure. |
|
283 | + * @since 3.0.0 |
|
284 | + */ |
|
285 | + public function get_next_step_link( $step = '' ) { |
|
286 | + if ( ! $step ) { |
|
287 | + $step = $this->step; |
|
288 | + } |
|
289 | + |
|
290 | + $keys = array_keys( $this->steps ); |
|
291 | + if ( end( $keys ) === $step ) { |
|
292 | + return admin_url(); |
|
293 | + } |
|
294 | + |
|
295 | + $step_index = array_search( $step, $keys ); |
|
296 | + if ( false === $step_index ) { |
|
297 | + return ''; |
|
298 | + } |
|
299 | + |
|
300 | + return remove_query_arg( 'settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ) ); |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Setup maps api. |
|
305 | + * |
|
306 | + * @since 2.0.0 |
|
307 | + */ |
|
308 | + public function setup_business() { |
|
309 | + $next_url = $this->get_next_step_link(); |
|
310 | + $wizard = $this; |
|
311 | + $page = 'wpinv_settings_general_main'; |
|
312 | + $section = 'wpinv_settings_general_main'; |
|
313 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Default Location settings. |
|
318 | + * |
|
319 | + * @since 2.0.0 |
|
320 | + */ |
|
321 | + public function setup_currency() { |
|
322 | + $next_url = $this->get_next_step_link(); |
|
323 | + $wizard = $this; |
|
324 | + $page = 'wpinv_settings_general_currency_section'; |
|
325 | + $section = 'wpinv_settings_general_currency_section'; |
|
326 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * Installation of recommended plugins. |
|
331 | + * |
|
332 | + * @since 1.0.0 |
|
333 | + */ |
|
334 | + public function setup_recommend() { |
|
335 | + $next_url = $this->get_next_step_link(); |
|
336 | + $recommended_plugins = self::get_recommend_wp_plugins(); |
|
337 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * A list of recommended wp.org plugins. |
|
342 | + * @return array |
|
343 | + */ |
|
344 | + public static function get_recommend_wp_plugins() { |
|
345 | + return array( |
|
346 | + 'ayecode-connect' => array( |
|
347 | + 'file' => 'ayecode-connect/ayecode-connect.php', |
|
348 | + 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
|
349 | + 'slug' => 'ayecode-connect', |
|
350 | + 'name' => 'AyeCode Connect', |
|
351 | + 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'invoicing' ), |
|
352 | + ), |
|
353 | + 'invoicing-quotes' => array( |
|
354 | + 'file' => 'invoicing-quotes/wpinv-quote.php', |
|
355 | + 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
|
356 | + 'slug' => 'invoicing-quotes', |
|
357 | + 'name' => 'Customer Quotes', |
|
358 | + 'desc' => __( 'Create & Send Quotes to Customers and have them accept and pay.', 'invoicing' ), |
|
359 | + ), |
|
360 | + 'userswp' => array( |
|
361 | + 'file' => 'userswp/userswp.php', |
|
362 | + 'url' => 'https://wordpress.org/plugins/userswp/', |
|
363 | + 'slug' => 'userswp', |
|
364 | + 'name' => 'UsersWP', |
|
365 | + 'desc' => __( 'Frontend user login and registration as well as slick profile pages.', 'invoicing' ), |
|
366 | + ), |
|
367 | + ); |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * Dummy Data setup. |
|
372 | + * |
|
373 | + * @since 2.4.0 |
|
374 | + */ |
|
375 | + public function setup_payments() { |
|
376 | + $next_url = $this->get_next_step_link(); |
|
377 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Dummy data save. |
|
382 | + * |
|
383 | + * This is done via ajax so we just pass onto the next step. |
|
384 | + * |
|
385 | + * @since 2.0.0 |
|
386 | + */ |
|
387 | + public function setup_payments_save() { |
|
388 | + check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
389 | + wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
390 | + |
|
391 | + if ( ! empty( $_POST['paypal-email'] ) ) { |
|
392 | + wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
393 | + wpinv_update_option( 'paypal_active', 1 ); |
|
394 | + wpinv_update_option( 'paypal_sandbox', 0 ); |
|
395 | + } |
|
396 | + |
|
397 | + wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
398 | + exit; |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * Final step. |
|
403 | + * |
|
404 | + * @since 2.0.0 |
|
405 | + */ |
|
406 | + public function setup_ready() { |
|
407 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
408 | + } |
|
409 | 409 | |
410 | 410 | } |
411 | 411 |
@@ -31,21 +31,21 @@ discard block |
||
31 | 31 | // Item name. |
32 | 32 | if ( 'name' == $column ) { |
33 | 33 | |
34 | - // Display the name. |
|
35 | - echo '<div class="mb-1">' . esc_html( $fee['name'] ) . '</div>'; |
|
34 | + // Display the name. |
|
35 | + echo '<div class="mb-1">' . esc_html( $fee['name'] ) . '</div>'; |
|
36 | 36 | |
37 | - // And an optional description. |
|
38 | - $description = empty( $fee['description'] ) ? esc_html__( 'Fee', 'invoicing' ) : esc_html( $fee['description'] ); |
|
39 | - echo wp_kses_post( "<small class='form-text text-muted pr-2 m-0'>$description</small>" ); |
|
37 | + // And an optional description. |
|
38 | + $description = empty( $fee['description'] ) ? esc_html__( 'Fee', 'invoicing' ) : esc_html( $fee['description'] ); |
|
39 | + echo wp_kses_post( "<small class='form-text text-muted pr-2 m-0'>$description</small>" ); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
43 | 43 | // Item price. |
44 | 44 | if ( 'price' == $column ) { |
45 | 45 | |
46 | - // Display the item price (or recurring price if this is a renewal invoice) |
|
47 | - if ( $invoice->is_recurring() && $invoice->is_renewal() ) { |
|
48 | - wpinv_the_price( $fee['recurring_fee'], $invoice->get_currency() ); |
|
46 | + // Display the item price (or recurring price if this is a renewal invoice) |
|
47 | + if ( $invoice->is_recurring() && $invoice->is_renewal() ) { |
|
48 | + wpinv_the_price( $fee['recurring_fee'], $invoice->get_currency() ); |
|
49 | 49 | } else { |
50 | 50 | wpinv_the_price( $fee['initial_fee'], $invoice->get_currency() ); |
51 | 51 | } |
@@ -53,20 +53,20 @@ discard block |
||
53 | 53 | |
54 | 54 | // Item quantity. |
55 | 55 | if ( 'quantity' == $column ) { |
56 | - echo '—'; |
|
56 | + echo '—'; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | // Item tax. |
60 | 60 | if ( 'tax_rate' == $column ) { |
61 | - echo '—'; |
|
61 | + echo '—'; |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | // Item sub total. |
65 | 65 | if ( 'subtotal' == $column ) { |
66 | 66 | |
67 | - // Display the item price (or recurring price if this is a renewal invoice) |
|
68 | - if ( $invoice->is_recurring() && $invoice->is_renewal() ) { |
|
69 | - wpinv_the_price( $fee['recurring_fee'], $invoice->get_currency() ); |
|
67 | + // Display the item price (or recurring price if this is a renewal invoice) |
|
68 | + if ( $invoice->is_recurring() && $invoice->is_renewal() ) { |
|
69 | + wpinv_the_price( $fee['recurring_fee'], $invoice->get_currency() ); |
|
70 | 70 | } else { |
71 | 71 | wpinv_the_price( $fee['initial_fee'], $invoice->get_currency() ); |
72 | 72 | } |
@@ -64,8 +64,8 @@ |
||
64 | 64 | $description = wpinv_get_gateway_description( $gateway ); |
65 | 65 | |
66 | 66 | if ( wpinv_is_test_mode( $gateway ) ) { |
67 | - $sandbox_notice = apply_filters( "getpaid_{$gateway}_sandbox_notice", __( 'SANDBOX ENABLED: No real payments will occur.', 'invoicing' ) ); |
|
68 | - $description = "$description $sandbox_notice"; |
|
67 | + $sandbox_notice = apply_filters( "getpaid_{$gateway}_sandbox_notice", __( 'SANDBOX ENABLED: No real payments will occur.', 'invoicing' ) ); |
|
68 | + $description = "$description $sandbox_notice"; |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | echo wp_kses_post( wpautop( $description ) ); |
@@ -30,40 +30,40 @@ |
||
30 | 30 | // Item name. |
31 | 31 | if ( 'name' == $column ) { |
32 | 32 | |
33 | - // Display the name. |
|
34 | - echo '<div class="wpinv_email_cart_item_title">' . esc_html( $item->get_name() ) . '</div>'; |
|
33 | + // Display the name. |
|
34 | + echo '<div class="wpinv_email_cart_item_title">' . esc_html( $item->get_name() ) . '</div>'; |
|
35 | 35 | |
36 | - // And an optional description. |
|
37 | - $description = $item->get_description(); |
|
36 | + // And an optional description. |
|
37 | + $description = $item->get_description(); |
|
38 | 38 | |
39 | - if ( ! empty( $description ) ) { |
|
40 | - echo "<p class='small'>" . wp_kses_post( $description ) . "</p>"; |
|
39 | + if ( ! empty( $description ) ) { |
|
40 | + echo "<p class='small'>" . wp_kses_post( $description ) . "</p>"; |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | // Item price. |
45 | 45 | if ( 'price' == $column ) { |
46 | 46 | |
47 | - // Display the item price (or recurring price if this is a renewal invoice) |
|
48 | - $price = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
|
49 | - wpinv_the_price( $price, $invoice->get_currency() ); |
|
47 | + // Display the item price (or recurring price if this is a renewal invoice) |
|
48 | + $price = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
|
49 | + wpinv_the_price( $price, $invoice->get_currency() ); |
|
50 | 50 | |
51 | 51 | } |
52 | 52 | |
53 | 53 | // Item quantity. |
54 | 54 | if ( 'quantity' == $column ) { |
55 | - echo (float) $item->get_quantity(); |
|
55 | + echo (float) $item->get_quantity(); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | // Tax rate. |
59 | 59 | if ( 'tax_rate' == $column ) { |
60 | - echo floatval( round( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%'; |
|
60 | + echo floatval( round( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%'; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | // Item sub total. |
64 | 64 | if ( 'subtotal' == $column ) { |
65 | - $subtotal = $invoice->is_renewal() ? $item->get_recurring_sub_total() : $item->get_sub_total(); |
|
66 | - wpinv_the_price( $subtotal, $invoice->get_currency() ); |
|
65 | + $subtotal = $invoice->is_renewal() ? $item->get_recurring_sub_total() : $item->get_sub_total(); |
|
66 | + wpinv_the_price( $subtotal, $invoice->get_currency() ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | // Fires when printing a line item column. |