@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | */ |
15 | 15 | function wpinv_subscriptions_page() { |
16 | 16 | |
17 | - ?> |
|
17 | + ?> |
|
18 | 18 | |
19 | 19 | <div class="wrap"> |
20 | 20 | <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
@@ -22,27 +22,27 @@ discard block |
||
22 | 22 | |
23 | 23 | <?php |
24 | 24 | |
25 | - // Verify user permissions. |
|
26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
25 | + // Verify user permissions. |
|
26 | + if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
27 | 27 | |
28 | - echo aui()->alert( |
|
29 | - array( |
|
30 | - 'type' => 'danger', |
|
31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
32 | - ) |
|
33 | - ); |
|
28 | + echo aui()->alert( |
|
29 | + array( |
|
30 | + 'type' => 'danger', |
|
31 | + 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
32 | + ) |
|
33 | + ); |
|
34 | 34 | |
35 | - } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
35 | + } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
36 | 36 | |
37 | - // Display a single subscription. |
|
38 | - wpinv_recurring_subscription_details(); |
|
39 | - } else { |
|
37 | + // Display a single subscription. |
|
38 | + wpinv_recurring_subscription_details(); |
|
39 | + } else { |
|
40 | 40 | |
41 | - // Display a list of available subscriptions. |
|
42 | - getpaid_print_subscriptions_list(); |
|
43 | - } |
|
41 | + // Display a list of available subscriptions. |
|
42 | + getpaid_print_subscriptions_list(); |
|
43 | + } |
|
44 | 44 | |
45 | - ?> |
|
45 | + ?> |
|
46 | 46 | |
47 | 47 | </div> |
48 | 48 | </div> |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | */ |
60 | 60 | function getpaid_print_subscriptions_list() { |
61 | 61 | |
62 | - $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
63 | - $subscribers_table->prepare_items(); |
|
62 | + $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
63 | + $subscribers_table->prepare_items(); |
|
64 | 64 | |
65 | - ?> |
|
65 | + ?> |
|
66 | 66 | <?php $subscribers_table->views(); ?> |
67 | 67 | <form id="subscribers-filter" class="bsui" method="get"> |
68 | 68 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
@@ -81,41 +81,41 @@ discard block |
||
81 | 81 | */ |
82 | 82 | function wpinv_recurring_subscription_details() { |
83 | 83 | |
84 | - // Fetch the subscription. |
|
85 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
86 | - if ( ! $sub->exists() ) { |
|
84 | + // Fetch the subscription. |
|
85 | + $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
86 | + if ( ! $sub->exists() ) { |
|
87 | 87 | |
88 | - echo aui()->alert( |
|
89 | - array( |
|
90 | - 'type' => 'danger', |
|
91 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
92 | - ) |
|
93 | - ); |
|
88 | + echo aui()->alert( |
|
89 | + array( |
|
90 | + 'type' => 'danger', |
|
91 | + 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
92 | + ) |
|
93 | + ); |
|
94 | 94 | |
95 | - return; |
|
96 | - } |
|
95 | + return; |
|
96 | + } |
|
97 | 97 | |
98 | - // Use metaboxes to display the subscription details. |
|
99 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
100 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
98 | + // Use metaboxes to display the subscription details. |
|
99 | + add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
100 | + add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
101 | 101 | |
102 | - $subscription_id = $sub->get_id(); |
|
103 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
104 | - $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
102 | + $subscription_id = $sub->get_id(); |
|
103 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
104 | + $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
105 | 105 | |
106 | - if ( 1 < count( $subscription_groups ) ) { |
|
107 | - add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
108 | - } |
|
106 | + if ( 1 < count( $subscription_groups ) ) { |
|
107 | + add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
108 | + } |
|
109 | 109 | |
110 | - if ( ! empty( $subscription_group ) ) { |
|
111 | - add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
112 | - } |
|
110 | + if ( ! empty( $subscription_group ) ) { |
|
111 | + add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
112 | + } |
|
113 | 113 | |
114 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
114 | + add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
115 | 115 | |
116 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
116 | + do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
117 | 117 | |
118 | - ?> |
|
118 | + ?> |
|
119 | 119 | |
120 | 120 | <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
121 | 121 | |
@@ -155,45 +155,45 @@ discard block |
||
155 | 155 | */ |
156 | 156 | function getpaid_admin_subscription_details_metabox( $sub ) { |
157 | 157 | |
158 | - // Subscription items. |
|
159 | - $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
160 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
161 | - |
|
162 | - // Prepare subscription detail columns. |
|
163 | - $fields = apply_filters( |
|
164 | - 'getpaid_subscription_admin_page_fields', |
|
165 | - array( |
|
166 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
167 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
168 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
169 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
170 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
171 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
172 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
173 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
174 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
175 | - 'status' => __( 'Status', 'invoicing' ), |
|
176 | - ) |
|
177 | - ); |
|
178 | - |
|
179 | - if ( ! $sub->is_active() ) { |
|
180 | - |
|
181 | - if ( isset( $fields['renews_on'] ) ) { |
|
182 | - unset( $fields['renews_on'] ); |
|
183 | - } |
|
184 | - |
|
185 | - if ( isset( $fields['gateway'] ) ) { |
|
186 | - unset( $fields['gateway'] ); |
|
187 | - } |
|
188 | - |
|
189 | - } |
|
190 | - |
|
191 | - $profile_id = $sub->get_profile_id(); |
|
192 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
193 | - unset( $fields['profile_id'] ); |
|
194 | - } |
|
195 | - |
|
196 | - ?> |
|
158 | + // Subscription items. |
|
159 | + $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
160 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
161 | + |
|
162 | + // Prepare subscription detail columns. |
|
163 | + $fields = apply_filters( |
|
164 | + 'getpaid_subscription_admin_page_fields', |
|
165 | + array( |
|
166 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
167 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
168 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
169 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
170 | + 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
171 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
172 | + 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
173 | + 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
174 | + 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
175 | + 'status' => __( 'Status', 'invoicing' ), |
|
176 | + ) |
|
177 | + ); |
|
178 | + |
|
179 | + if ( ! $sub->is_active() ) { |
|
180 | + |
|
181 | + if ( isset( $fields['renews_on'] ) ) { |
|
182 | + unset( $fields['renews_on'] ); |
|
183 | + } |
|
184 | + |
|
185 | + if ( isset( $fields['gateway'] ) ) { |
|
186 | + unset( $fields['gateway'] ); |
|
187 | + } |
|
188 | + |
|
189 | + } |
|
190 | + |
|
191 | + $profile_id = $sub->get_profile_id(); |
|
192 | + if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
193 | + unset( $fields['profile_id'] ); |
|
194 | + } |
|
195 | + |
|
196 | + ?> |
|
197 | 197 | |
198 | 198 | <table class="table table-borderless" style="font-size: 14px;"> |
199 | 199 | <tbody> |
@@ -227,20 +227,20 @@ discard block |
||
227 | 227 | */ |
228 | 228 | function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
229 | 229 | |
230 | - $username = __( '(Missing User)', 'invoicing' ); |
|
230 | + $username = __( '(Missing User)', 'invoicing' ); |
|
231 | 231 | |
232 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
233 | - if ( $user ) { |
|
232 | + $user = get_userdata( $subscription->get_customer_id() ); |
|
233 | + if ( $user ) { |
|
234 | 234 | |
235 | - $username = sprintf( |
|
236 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
237 | - absint( $user->ID ), |
|
238 | - ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
239 | - ); |
|
235 | + $username = sprintf( |
|
236 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
237 | + absint( $user->ID ), |
|
238 | + ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
239 | + ); |
|
240 | 240 | |
241 | - } |
|
241 | + } |
|
242 | 242 | |
243 | - echo $username; |
|
243 | + echo $username; |
|
244 | 244 | } |
245 | 245 | add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
246 | 246 | |
@@ -250,8 +250,8 @@ discard block |
||
250 | 250 | * @param WPInv_Subscription $subscription |
251 | 251 | */ |
252 | 252 | function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
253 | - $amount = wp_kses_post( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
254 | - echo "<span>$amount</span>"; |
|
253 | + $amount = wp_kses_post( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
254 | + echo "<span>$amount</span>"; |
|
255 | 255 | } |
256 | 256 | add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
257 | 257 | |
@@ -262,11 +262,11 @@ discard block |
||
262 | 262 | */ |
263 | 263 | function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
264 | 264 | |
265 | - printf( |
|
266 | - '<a href="%s">#%s</a>', |
|
267 | - esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $subscription->get_id() ) ) ), |
|
268 | - absint( $subscription->get_id() ) |
|
269 | - ); |
|
265 | + printf( |
|
266 | + '<a href="%s">#%s</a>', |
|
267 | + esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $subscription->get_id() ) ) ), |
|
268 | + absint( $subscription->get_id() ) |
|
269 | + ); |
|
270 | 270 | |
271 | 271 | } |
272 | 272 | add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * @param WPInv_Subscription $subscription |
278 | 278 | */ |
279 | 279 | function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
280 | - echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
280 | + echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
281 | 281 | } |
282 | 282 | add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
283 | 283 | |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * @param WPInv_Subscription $subscription |
288 | 288 | */ |
289 | 289 | function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
290 | - echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
290 | + echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
291 | 291 | } |
292 | 292 | add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
293 | 293 | |
@@ -297,8 +297,8 @@ discard block |
||
297 | 297 | * @param WPInv_Subscription $subscription |
298 | 298 | */ |
299 | 299 | function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
300 | - $max_bills = $subscription->get_bill_times(); |
|
301 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
300 | + $max_bills = $subscription->get_bill_times(); |
|
301 | + echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
302 | 302 | } |
303 | 303 | add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
304 | 304 | /** |
@@ -309,13 +309,13 @@ discard block |
||
309 | 309 | */ |
310 | 310 | function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) { |
311 | 311 | |
312 | - if ( empty( $subscription_group ) ) { |
|
313 | - echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ); |
|
314 | - return; |
|
315 | - } |
|
312 | + if ( empty( $subscription_group ) ) { |
|
313 | + echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ); |
|
314 | + return; |
|
315 | + } |
|
316 | 316 | |
317 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
318 | - echo implode( ' | ', $markup ); |
|
317 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
318 | + echo implode( ' | ', $markup ); |
|
319 | 319 | |
320 | 320 | } |
321 | 321 | add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 ); |
@@ -327,13 +327,13 @@ discard block |
||
327 | 327 | */ |
328 | 328 | function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
329 | 329 | |
330 | - $gateway = $subscription->get_gateway(); |
|
330 | + $gateway = $subscription->get_gateway(); |
|
331 | 331 | |
332 | - if ( ! empty( $gateway ) ) { |
|
333 | - echo esc_html( wpinv_get_gateway_admin_label( $gateway ) ); |
|
334 | - } else { |
|
335 | - echo "—"; |
|
336 | - } |
|
332 | + if ( ! empty( $gateway ) ) { |
|
333 | + echo esc_html( wpinv_get_gateway_admin_label( $gateway ) ); |
|
334 | + } else { |
|
335 | + echo "—"; |
|
336 | + } |
|
337 | 337 | |
338 | 338 | } |
339 | 339 | add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | * @param WPInv_Subscription $subscription |
345 | 345 | */ |
346 | 346 | function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
347 | - echo $subscription->get_status_label_html(); |
|
347 | + echo $subscription->get_status_label_html(); |
|
348 | 348 | } |
349 | 349 | add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
350 | 350 | |
@@ -355,29 +355,29 @@ discard block |
||
355 | 355 | */ |
356 | 356 | function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
357 | 357 | |
358 | - $profile_id = $subscription->get_profile_id(); |
|
359 | - |
|
360 | - $input = aui()->input( |
|
361 | - array( |
|
362 | - 'type' => 'text', |
|
363 | - 'id' => 'wpinv_subscription_profile_id', |
|
364 | - 'name' => 'wpinv_subscription_profile_id', |
|
365 | - 'label' => __( 'Profile Id', 'invoicing' ), |
|
366 | - 'label_type' => 'hidden', |
|
367 | - 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
368 | - 'value' => esc_attr( $profile_id ), |
|
369 | - 'input_group_right' => '', |
|
370 | - 'no_wrap' => true, |
|
371 | - ) |
|
372 | - ); |
|
373 | - |
|
374 | - echo str_ireplace( 'form-control', 'regular-text', $input ); |
|
375 | - |
|
376 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
377 | - if ( ! empty( $url ) ) { |
|
378 | - $url = esc_url_raw( $url ); |
|
379 | - echo ' <a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
380 | - } |
|
358 | + $profile_id = $subscription->get_profile_id(); |
|
359 | + |
|
360 | + $input = aui()->input( |
|
361 | + array( |
|
362 | + 'type' => 'text', |
|
363 | + 'id' => 'wpinv_subscription_profile_id', |
|
364 | + 'name' => 'wpinv_subscription_profile_id', |
|
365 | + 'label' => __( 'Profile Id', 'invoicing' ), |
|
366 | + 'label_type' => 'hidden', |
|
367 | + 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
368 | + 'value' => esc_attr( $profile_id ), |
|
369 | + 'input_group_right' => '', |
|
370 | + 'no_wrap' => true, |
|
371 | + ) |
|
372 | + ); |
|
373 | + |
|
374 | + echo str_ireplace( 'form-control', 'regular-text', $input ); |
|
375 | + |
|
376 | + $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
377 | + if ( ! empty( $url ) ) { |
|
378 | + $url = esc_url_raw( $url ); |
|
379 | + echo ' <a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
380 | + } |
|
381 | 381 | |
382 | 382 | } |
383 | 383 | add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
@@ -389,39 +389,39 @@ discard block |
||
389 | 389 | */ |
390 | 390 | function getpaid_admin_subscription_update_metabox( $subscription ) { |
391 | 391 | |
392 | - ?> |
|
392 | + ?> |
|
393 | 393 | <div class="mt-3"> |
394 | 394 | |
395 | 395 | <?php |
396 | - echo aui()->select( |
|
397 | - array( |
|
398 | - 'options' => getpaid_get_subscription_statuses(), |
|
399 | - 'name' => 'subscription_status', |
|
400 | - 'id' => 'subscription_status_update_select', |
|
401 | - 'required' => true, |
|
402 | - 'no_wrap' => false, |
|
403 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
404 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
405 | - 'select2' => true, |
|
406 | - 'value' => $subscription->get_status( 'edit' ), |
|
407 | - ) |
|
408 | - ); |
|
409 | - ?> |
|
396 | + echo aui()->select( |
|
397 | + array( |
|
398 | + 'options' => getpaid_get_subscription_statuses(), |
|
399 | + 'name' => 'subscription_status', |
|
400 | + 'id' => 'subscription_status_update_select', |
|
401 | + 'required' => true, |
|
402 | + 'no_wrap' => false, |
|
403 | + 'label' => __( 'Subscription Status', 'invoicing' ), |
|
404 | + 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
405 | + 'select2' => true, |
|
406 | + 'value' => $subscription->get_status( 'edit' ), |
|
407 | + ) |
|
408 | + ); |
|
409 | + ?> |
|
410 | 410 | |
411 | 411 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
412 | 412 | |
413 | 413 | <?php |
414 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
414 | + submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
415 | 415 | |
416 | - $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
417 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
418 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
416 | + $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
417 | + $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
418 | + $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
419 | 419 | |
420 | - if ( $subscription->is_active() ) { |
|
421 | - echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
422 | - } |
|
420 | + if ( $subscription->is_active() ) { |
|
421 | + echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
422 | + } |
|
423 | 423 | |
424 | - echo '</div></div>'; |
|
424 | + echo '</div></div>'; |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -432,33 +432,33 @@ discard block |
||
432 | 432 | */ |
433 | 433 | function getpaid_admin_subscription_invoice_details_metabox( $subscription, $strict = true ) { |
434 | 434 | |
435 | - $columns = apply_filters( |
|
436 | - 'getpaid_subscription_related_invoices_columns', |
|
437 | - array( |
|
438 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
439 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
440 | - 'date' => __( 'Date', 'invoicing' ), |
|
441 | - 'status' => __( 'Status', 'invoicing' ), |
|
442 | - 'total' => __( 'Total', 'invoicing' ), |
|
443 | - ), |
|
444 | - $subscription |
|
445 | - ); |
|
446 | - |
|
447 | - // Prepare the invoices. |
|
448 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
449 | - $parent = $subscription->get_parent_invoice(); |
|
450 | - |
|
451 | - if ( $parent->exists() ) { |
|
452 | - $payments = array_merge( array( $parent ), $payments ); |
|
453 | - } |
|
454 | - |
|
455 | - $table_class = 'w-100 bg-white'; |
|
456 | - |
|
457 | - if ( ! is_admin() ) { |
|
458 | - $table_class = 'table table-bordered'; |
|
459 | - } |
|
460 | - |
|
461 | - ?> |
|
435 | + $columns = apply_filters( |
|
436 | + 'getpaid_subscription_related_invoices_columns', |
|
437 | + array( |
|
438 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
439 | + 'relationship' => __( 'Relationship', 'invoicing' ), |
|
440 | + 'date' => __( 'Date', 'invoicing' ), |
|
441 | + 'status' => __( 'Status', 'invoicing' ), |
|
442 | + 'total' => __( 'Total', 'invoicing' ), |
|
443 | + ), |
|
444 | + $subscription |
|
445 | + ); |
|
446 | + |
|
447 | + // Prepare the invoices. |
|
448 | + $payments = $subscription->get_child_payments( ! is_admin() ); |
|
449 | + $parent = $subscription->get_parent_invoice(); |
|
450 | + |
|
451 | + if ( $parent->exists() ) { |
|
452 | + $payments = array_merge( array( $parent ), $payments ); |
|
453 | + } |
|
454 | + |
|
455 | + $table_class = 'w-100 bg-white'; |
|
456 | + |
|
457 | + if ( ! is_admin() ) { |
|
458 | + $table_class = 'table table-bordered'; |
|
459 | + } |
|
460 | + |
|
461 | + ?> |
|
462 | 462 | <div class="m-0" style="overflow: auto;"> |
463 | 463 | |
464 | 464 | <table class="<?php echo $table_class; ?>"> |
@@ -466,14 +466,14 @@ discard block |
||
466 | 466 | <thead> |
467 | 467 | <tr> |
468 | 468 | <?php |
469 | - foreach ( $columns as $key => $label ) { |
|
470 | - $key = esc_attr( $key ); |
|
471 | - $label = esc_html( $label ); |
|
472 | - $class = 'text-left'; |
|
473 | - |
|
474 | - echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
475 | - } |
|
476 | - ?> |
|
469 | + foreach ( $columns as $key => $label ) { |
|
470 | + $key = esc_attr( $key ); |
|
471 | + $label = esc_html( $label ); |
|
472 | + $class = 'text-left'; |
|
473 | + |
|
474 | + echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
475 | + } |
|
476 | + ?> |
|
477 | 477 | </tr> |
478 | 478 | </thead> |
479 | 479 | |
@@ -489,73 +489,73 @@ discard block |
||
489 | 489 | |
490 | 490 | <?php |
491 | 491 | |
492 | - foreach( $payments as $payment ) : |
|
492 | + foreach( $payments as $payment ) : |
|
493 | 493 | |
494 | - // Ensure that we have an invoice. |
|
495 | - $payment = new WPInv_Invoice( $payment ); |
|
494 | + // Ensure that we have an invoice. |
|
495 | + $payment = new WPInv_Invoice( $payment ); |
|
496 | 496 | |
497 | - // Abort if the invoice is invalid... |
|
498 | - if ( ! $payment->exists() ) { |
|
499 | - continue; |
|
500 | - } |
|
497 | + // Abort if the invoice is invalid... |
|
498 | + if ( ! $payment->exists() ) { |
|
499 | + continue; |
|
500 | + } |
|
501 | 501 | |
502 | - // ... or belongs to a different subscription. |
|
503 | - if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
504 | - continue; |
|
505 | - } |
|
502 | + // ... or belongs to a different subscription. |
|
503 | + if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
504 | + continue; |
|
505 | + } |
|
506 | 506 | |
507 | - echo '<tr>'; |
|
507 | + echo '<tr>'; |
|
508 | 508 | |
509 | - foreach ( array_keys( $columns ) as $key ) { |
|
509 | + foreach ( array_keys( $columns ) as $key ) { |
|
510 | 510 | |
511 | - $class = 'text-left'; |
|
511 | + $class = 'text-left'; |
|
512 | 512 | |
513 | - echo "<td class='p-2 $class'>"; |
|
513 | + echo "<td class='p-2 $class'>"; |
|
514 | 514 | |
515 | - switch( $key ) { |
|
515 | + switch( $key ) { |
|
516 | 516 | |
517 | - case 'total': |
|
518 | - echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>'; |
|
519 | - break; |
|
517 | + case 'total': |
|
518 | + echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>'; |
|
519 | + break; |
|
520 | 520 | |
521 | - case 'relationship': |
|
522 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
523 | - break; |
|
521 | + case 'relationship': |
|
522 | + echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
523 | + break; |
|
524 | 524 | |
525 | - case 'date': |
|
526 | - echo getpaid_format_date_value( $payment->get_date_created() ); |
|
527 | - break; |
|
525 | + case 'date': |
|
526 | + echo getpaid_format_date_value( $payment->get_date_created() ); |
|
527 | + break; |
|
528 | 528 | |
529 | - case 'status': |
|
529 | + case 'status': |
|
530 | 530 | |
531 | - $status = $payment->get_status_nicename(); |
|
532 | - if ( is_admin() ) { |
|
533 | - $status = $payment->get_status_label_html(); |
|
534 | - } |
|
531 | + $status = $payment->get_status_nicename(); |
|
532 | + if ( is_admin() ) { |
|
533 | + $status = $payment->get_status_label_html(); |
|
534 | + } |
|
535 | 535 | |
536 | - echo $status; |
|
537 | - break; |
|
536 | + echo $status; |
|
537 | + break; |
|
538 | 538 | |
539 | - case 'invoice': |
|
540 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
539 | + case 'invoice': |
|
540 | + $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
541 | 541 | |
542 | - if ( ! is_admin() ) { |
|
543 | - $link = esc_url( $payment->get_view_url() ); |
|
544 | - } |
|
542 | + if ( ! is_admin() ) { |
|
543 | + $link = esc_url( $payment->get_view_url() ); |
|
544 | + } |
|
545 | 545 | |
546 | - $invoice = esc_html( $payment->get_number() ); |
|
547 | - echo "<a href='$link'>$invoice</a>"; |
|
548 | - break; |
|
549 | - } |
|
546 | + $invoice = esc_html( $payment->get_number() ); |
|
547 | + echo "<a href='$link'>$invoice</a>"; |
|
548 | + break; |
|
549 | + } |
|
550 | 550 | |
551 | - echo '</td>'; |
|
551 | + echo '</td>'; |
|
552 | 552 | |
553 | - } |
|
553 | + } |
|
554 | 554 | |
555 | - echo '</tr>'; |
|
555 | + echo '</tr>'; |
|
556 | 556 | |
557 | - endforeach; |
|
558 | - ?> |
|
557 | + endforeach; |
|
558 | + ?> |
|
559 | 559 | |
560 | 560 | </tbody> |
561 | 561 | |
@@ -573,42 +573,42 @@ discard block |
||
573 | 573 | */ |
574 | 574 | function getpaid_admin_subscription_item_details_metabox( $subscription ) { |
575 | 575 | |
576 | - // Fetch the subscription group. |
|
577 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
576 | + // Fetch the subscription group. |
|
577 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
578 | 578 | |
579 | - if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
580 | - return; |
|
581 | - } |
|
579 | + if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
580 | + return; |
|
581 | + } |
|
582 | 582 | |
583 | - // Prepare table columns. |
|
584 | - $columns = apply_filters( |
|
585 | - 'getpaid_subscription_item_details_columns', |
|
586 | - array( |
|
587 | - 'item_name' => __( 'Item', 'invoicing' ), |
|
588 | - 'price' => __( 'Price', 'invoicing' ), |
|
589 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
590 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
591 | - //'initial' => __( 'Initial Amount', 'invoicing' ), |
|
592 | - 'recurring' => __( 'Subtotal', 'invoicing' ), |
|
593 | - ), |
|
594 | - $subscription |
|
595 | - ); |
|
583 | + // Prepare table columns. |
|
584 | + $columns = apply_filters( |
|
585 | + 'getpaid_subscription_item_details_columns', |
|
586 | + array( |
|
587 | + 'item_name' => __( 'Item', 'invoicing' ), |
|
588 | + 'price' => __( 'Price', 'invoicing' ), |
|
589 | + 'tax' => __( 'Tax', 'invoicing' ), |
|
590 | + 'discount' => __( 'Discount', 'invoicing' ), |
|
591 | + //'initial' => __( 'Initial Amount', 'invoicing' ), |
|
592 | + 'recurring' => __( 'Subtotal', 'invoicing' ), |
|
593 | + ), |
|
594 | + $subscription |
|
595 | + ); |
|
596 | 596 | |
597 | - // Prepare the invoices. |
|
597 | + // Prepare the invoices. |
|
598 | 598 | |
599 | - $invoice = $subscription->get_parent_invoice(); |
|
599 | + $invoice = $subscription->get_parent_invoice(); |
|
600 | 600 | |
601 | - if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
602 | - unset( $columns['tax'] ); |
|
603 | - } |
|
601 | + if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
602 | + unset( $columns['tax'] ); |
|
603 | + } |
|
604 | 604 | |
605 | - $table_class = 'w-100 bg-white'; |
|
605 | + $table_class = 'w-100 bg-white'; |
|
606 | 606 | |
607 | - if ( ! is_admin() ) { |
|
608 | - $table_class = 'table table-bordered'; |
|
609 | - } |
|
607 | + if ( ! is_admin() ) { |
|
608 | + $table_class = 'table table-bordered'; |
|
609 | + } |
|
610 | 610 | |
611 | - ?> |
|
611 | + ?> |
|
612 | 612 | <div class="m-0" style="overflow: auto;"> |
613 | 613 | |
614 | 614 | <table class="<?php echo $table_class; ?>"> |
@@ -617,14 +617,14 @@ discard block |
||
617 | 617 | <tr> |
618 | 618 | <?php |
619 | 619 | |
620 | - foreach ( $columns as $key => $label ) { |
|
621 | - $key = esc_attr( $key ); |
|
622 | - $label = esc_html( $label ); |
|
623 | - $class = 'text-left'; |
|
620 | + foreach ( $columns as $key => $label ) { |
|
621 | + $key = esc_attr( $key ); |
|
622 | + $label = esc_html( $label ); |
|
623 | + $class = 'text-left'; |
|
624 | 624 | |
625 | - echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
626 | - } |
|
627 | - ?> |
|
625 | + echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
626 | + } |
|
627 | + ?> |
|
628 | 628 | </tr> |
629 | 629 | </thead> |
630 | 630 | |
@@ -632,106 +632,106 @@ discard block |
||
632 | 632 | |
633 | 633 | <?php |
634 | 634 | |
635 | - foreach( $subscription_group['items'] as $subscription_group_item ) : |
|
635 | + foreach( $subscription_group['items'] as $subscription_group_item ) : |
|
636 | 636 | |
637 | - echo '<tr>'; |
|
637 | + echo '<tr>'; |
|
638 | 638 | |
639 | - foreach ( array_keys( $columns ) as $key ) { |
|
639 | + foreach ( array_keys( $columns ) as $key ) { |
|
640 | 640 | |
641 | - $class = 'text-left'; |
|
641 | + $class = 'text-left'; |
|
642 | 642 | |
643 | - echo "<td class='p-2 $class'>"; |
|
643 | + echo "<td class='p-2 $class'>"; |
|
644 | 644 | |
645 | - switch( $key ) { |
|
645 | + switch( $key ) { |
|
646 | 646 | |
647 | - case 'item_name': |
|
648 | - $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
649 | - $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
647 | + case 'item_name': |
|
648 | + $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
649 | + $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
650 | 650 | |
651 | - if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
652 | - echo esc_html( $item_name ); |
|
653 | - } else { |
|
654 | - printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
655 | - } |
|
651 | + if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
652 | + echo esc_html( $item_name ); |
|
653 | + } else { |
|
654 | + printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
655 | + } |
|
656 | 656 | |
657 | - break; |
|
657 | + break; |
|
658 | 658 | |
659 | - case 'price': |
|
660 | - echo wpinv_price( $subscription_group_item['item_price'], $invoice->get_currency() ); |
|
661 | - break; |
|
659 | + case 'price': |
|
660 | + echo wpinv_price( $subscription_group_item['item_price'], $invoice->get_currency() ); |
|
661 | + break; |
|
662 | 662 | |
663 | - case 'tax': |
|
664 | - echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
665 | - break; |
|
663 | + case 'tax': |
|
664 | + echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
665 | + break; |
|
666 | 666 | |
667 | - case 'discount': |
|
668 | - echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
669 | - break; |
|
667 | + case 'discount': |
|
668 | + echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
669 | + break; |
|
670 | 670 | |
671 | - case 'initial': |
|
672 | - echo wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ); |
|
673 | - break; |
|
671 | + case 'initial': |
|
672 | + echo wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ); |
|
673 | + break; |
|
674 | 674 | |
675 | - case 'recurring': |
|
676 | - echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>'; |
|
677 | - break; |
|
675 | + case 'recurring': |
|
676 | + echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>'; |
|
677 | + break; |
|
678 | 678 | |
679 | - } |
|
679 | + } |
|
680 | 680 | |
681 | - echo '</td>'; |
|
681 | + echo '</td>'; |
|
682 | 682 | |
683 | - } |
|
683 | + } |
|
684 | 684 | |
685 | - echo '</tr>'; |
|
685 | + echo '</tr>'; |
|
686 | 686 | |
687 | - endforeach; |
|
687 | + endforeach; |
|
688 | 688 | |
689 | - foreach( $subscription_group['fees'] as $subscription_group_fee ) : |
|
689 | + foreach( $subscription_group['fees'] as $subscription_group_fee ) : |
|
690 | 690 | |
691 | - echo '<tr>'; |
|
691 | + echo '<tr>'; |
|
692 | 692 | |
693 | - foreach ( array_keys( $columns ) as $key ) { |
|
693 | + foreach ( array_keys( $columns ) as $key ) { |
|
694 | 694 | |
695 | - $class = 'text-left'; |
|
695 | + $class = 'text-left'; |
|
696 | 696 | |
697 | - echo "<td class='p-2 $class'>"; |
|
697 | + echo "<td class='p-2 $class'>"; |
|
698 | 698 | |
699 | - switch( $key ) { |
|
699 | + switch( $key ) { |
|
700 | 700 | |
701 | - case 'item_name': |
|
702 | - echo esc_html( $subscription_group_fee['name'] ); |
|
703 | - break; |
|
701 | + case 'item_name': |
|
702 | + echo esc_html( $subscription_group_fee['name'] ); |
|
703 | + break; |
|
704 | 704 | |
705 | - case 'price': |
|
706 | - echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
707 | - break; |
|
705 | + case 'price': |
|
706 | + echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
707 | + break; |
|
708 | 708 | |
709 | - case 'tax': |
|
710 | - echo "—"; |
|
711 | - break; |
|
709 | + case 'tax': |
|
710 | + echo "—"; |
|
711 | + break; |
|
712 | 712 | |
713 | - case 'discount': |
|
714 | - echo "—"; |
|
715 | - break; |
|
713 | + case 'discount': |
|
714 | + echo "—"; |
|
715 | + break; |
|
716 | 716 | |
717 | - case 'initial': |
|
718 | - echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
719 | - break; |
|
717 | + case 'initial': |
|
718 | + echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
719 | + break; |
|
720 | 720 | |
721 | - case 'recurring': |
|
722 | - echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>'; |
|
723 | - break; |
|
721 | + case 'recurring': |
|
722 | + echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>'; |
|
723 | + break; |
|
724 | 724 | |
725 | - } |
|
725 | + } |
|
726 | 726 | |
727 | - echo '</td>'; |
|
727 | + echo '</td>'; |
|
728 | 728 | |
729 | - } |
|
729 | + } |
|
730 | 730 | |
731 | - echo '</tr>'; |
|
731 | + echo '</tr>'; |
|
732 | 732 | |
733 | - endforeach; |
|
734 | - ?> |
|
733 | + endforeach; |
|
734 | + ?> |
|
735 | 735 | |
736 | 736 | </tbody> |
737 | 737 | |
@@ -750,38 +750,38 @@ discard block |
||
750 | 750 | */ |
751 | 751 | function getpaid_admin_subscription_related_subscriptions_metabox( $subscription, $skip_current = true ) { |
752 | 752 | |
753 | - // Fetch the subscription groups. |
|
754 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
755 | - |
|
756 | - if ( empty( $subscription_groups ) ) { |
|
757 | - return; |
|
758 | - } |
|
759 | - |
|
760 | - // Prepare table columns. |
|
761 | - $columns = apply_filters( |
|
762 | - 'getpaid_subscription_related_subscriptions_columns', |
|
763 | - array( |
|
764 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
765 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
766 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
767 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
768 | - 'item' => __( 'Items', 'invoicing' ), |
|
769 | - 'status' => __( 'Status', 'invoicing' ), |
|
770 | - ), |
|
771 | - $subscription |
|
772 | - ); |
|
773 | - |
|
774 | - if ( $subscription->get_status() == 'pending' ) { |
|
775 | - unset( $columns['start_date'], $columns['renewal_date'] ); |
|
776 | - } |
|
777 | - |
|
778 | - $table_class = 'w-100 bg-white'; |
|
779 | - |
|
780 | - if ( ! is_admin() ) { |
|
781 | - $table_class = 'table table-bordered'; |
|
782 | - } |
|
783 | - |
|
784 | - ?> |
|
753 | + // Fetch the subscription groups. |
|
754 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
755 | + |
|
756 | + if ( empty( $subscription_groups ) ) { |
|
757 | + return; |
|
758 | + } |
|
759 | + |
|
760 | + // Prepare table columns. |
|
761 | + $columns = apply_filters( |
|
762 | + 'getpaid_subscription_related_subscriptions_columns', |
|
763 | + array( |
|
764 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
765 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
766 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
767 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
768 | + 'item' => __( 'Items', 'invoicing' ), |
|
769 | + 'status' => __( 'Status', 'invoicing' ), |
|
770 | + ), |
|
771 | + $subscription |
|
772 | + ); |
|
773 | + |
|
774 | + if ( $subscription->get_status() == 'pending' ) { |
|
775 | + unset( $columns['start_date'], $columns['renewal_date'] ); |
|
776 | + } |
|
777 | + |
|
778 | + $table_class = 'w-100 bg-white'; |
|
779 | + |
|
780 | + if ( ! is_admin() ) { |
|
781 | + $table_class = 'table table-bordered'; |
|
782 | + } |
|
783 | + |
|
784 | + ?> |
|
785 | 785 | <div class="m-0" style="overflow: auto;"> |
786 | 786 | |
787 | 787 | <table class="<?php echo $table_class; ?>"> |
@@ -790,14 +790,14 @@ discard block |
||
790 | 790 | <tr> |
791 | 791 | <?php |
792 | 792 | |
793 | - foreach ( $columns as $key => $label ) { |
|
794 | - $key = esc_attr( $key ); |
|
795 | - $label = esc_html( $label ); |
|
796 | - $class = 'text-left'; |
|
793 | + foreach ( $columns as $key => $label ) { |
|
794 | + $key = esc_attr( $key ); |
|
795 | + $label = esc_html( $label ); |
|
796 | + $class = 'text-left'; |
|
797 | 797 | |
798 | - echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
799 | - } |
|
800 | - ?> |
|
798 | + echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
799 | + } |
|
800 | + ?> |
|
801 | 801 | </tr> |
802 | 802 | </thead> |
803 | 803 | |
@@ -805,74 +805,74 @@ discard block |
||
805 | 805 | |
806 | 806 | <?php |
807 | 807 | |
808 | - foreach( $subscription_groups as $subscription_group ) : |
|
808 | + foreach( $subscription_groups as $subscription_group ) : |
|
809 | 809 | |
810 | - // Do not list current subscription. |
|
811 | - if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
812 | - continue; |
|
813 | - } |
|
810 | + // Do not list current subscription. |
|
811 | + if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
812 | + continue; |
|
813 | + } |
|
814 | 814 | |
815 | - // Ensure the subscription exists. |
|
816 | - $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
815 | + // Ensure the subscription exists. |
|
816 | + $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
817 | 817 | |
818 | - if ( ! $_suscription->exists() ) { |
|
819 | - continue; |
|
820 | - } |
|
818 | + if ( ! $_suscription->exists() ) { |
|
819 | + continue; |
|
820 | + } |
|
821 | 821 | |
822 | - echo '<tr>'; |
|
822 | + echo '<tr>'; |
|
823 | 823 | |
824 | - foreach ( array_keys( $columns ) as $key ) { |
|
824 | + foreach ( array_keys( $columns ) as $key ) { |
|
825 | 825 | |
826 | - $class = 'text-left'; |
|
826 | + $class = 'text-left'; |
|
827 | 827 | |
828 | - echo "<td class='p-2 $class'>"; |
|
828 | + echo "<td class='p-2 $class'>"; |
|
829 | 829 | |
830 | - switch( $key ) { |
|
830 | + switch( $key ) { |
|
831 | 831 | |
832 | - case 'status': |
|
833 | - echo $_suscription->get_status_label_html(); |
|
834 | - break; |
|
832 | + case 'status': |
|
833 | + echo $_suscription->get_status_label_html(); |
|
834 | + break; |
|
835 | 835 | |
836 | - case 'item': |
|
837 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
838 | - echo implode( ' | ', $markup ); |
|
839 | - break; |
|
836 | + case 'item': |
|
837 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
838 | + echo implode( ' | ', $markup ); |
|
839 | + break; |
|
840 | 840 | |
841 | - case 'renewals': |
|
842 | - $max_bills = $_suscription->get_bill_times(); |
|
843 | - echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
844 | - break; |
|
841 | + case 'renewals': |
|
842 | + $max_bills = $_suscription->get_bill_times(); |
|
843 | + echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
844 | + break; |
|
845 | 845 | |
846 | - case 'renewal_date': |
|
847 | - echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "—"; |
|
848 | - break; |
|
846 | + case 'renewal_date': |
|
847 | + echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "—"; |
|
848 | + break; |
|
849 | 849 | |
850 | - case 'start_date': |
|
851 | - echo 'pending' == $_suscription->get_status() ? "—" : getpaid_format_date_value( $_suscription->get_date_created() ); |
|
852 | - break; |
|
850 | + case 'start_date': |
|
851 | + echo 'pending' == $_suscription->get_status() ? "—" : getpaid_format_date_value( $_suscription->get_date_created() ); |
|
852 | + break; |
|
853 | 853 | |
854 | - case 'subscription': |
|
855 | - $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
856 | - printf( |
|
857 | - '%1$s#%2$s%3$s', |
|
858 | - '<a href="' . esc_url( $url ) . '">', |
|
859 | - '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
|
860 | - '</a>' |
|
861 | - ); |
|
854 | + case 'subscription': |
|
855 | + $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
856 | + printf( |
|
857 | + '%1$s#%2$s%3$s', |
|
858 | + '<a href="' . esc_url( $url ) . '">', |
|
859 | + '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
|
860 | + '</a>' |
|
861 | + ); |
|
862 | 862 | |
863 | - echo WPInv_Subscriptions_List_Table::column_amount( $_suscription ); |
|
864 | - break; |
|
863 | + echo WPInv_Subscriptions_List_Table::column_amount( $_suscription ); |
|
864 | + break; |
|
865 | 865 | |
866 | - } |
|
866 | + } |
|
867 | 867 | |
868 | - echo '</td>'; |
|
868 | + echo '</td>'; |
|
869 | 869 | |
870 | - } |
|
870 | + } |
|
871 | 871 | |
872 | - echo '</tr>'; |
|
872 | + echo '</tr>'; |
|
873 | 873 | |
874 | - endforeach; |
|
875 | - ?> |
|
874 | + endforeach; |
|
875 | + ?> |
|
876 | 876 | |
877 | 877 | </tbody> |
878 | 878 |
@@ -17,45 +17,45 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class BP_GetPaid_Component extends BP_Component { |
19 | 19 | |
20 | - /** |
|
21 | - * Start the component setup process. |
|
22 | - * |
|
23 | - * @since 2.1.5 |
|
24 | - */ |
|
25 | - public function __construct() { |
|
26 | - parent::start( |
|
27 | - 'getpaid', |
|
28 | - 'GetPaid', |
|
29 | - buddypress()->plugin_dir, |
|
30 | - array( |
|
31 | - 'adminbar_myaccount_order' => 30, |
|
32 | - ) |
|
33 | - ); |
|
34 | - } |
|
20 | + /** |
|
21 | + * Start the component setup process. |
|
22 | + * |
|
23 | + * @since 2.1.5 |
|
24 | + */ |
|
25 | + public function __construct() { |
|
26 | + parent::start( |
|
27 | + 'getpaid', |
|
28 | + 'GetPaid', |
|
29 | + buddypress()->plugin_dir, |
|
30 | + array( |
|
31 | + 'adminbar_myaccount_order' => 30, |
|
32 | + ) |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Set up component global variables. |
|
38 | - * |
|
39 | - * @since 2.1.5 |
|
40 | - * |
|
41 | - * |
|
42 | - * @param array $args { |
|
43 | - * All values are optional. |
|
44 | - * @type string $slug The component slug. Used to construct certain URLs, such as 'friends' in |
|
45 | - * http://example.com/members/joe/friends/. Default: the value of $this->id. |
|
46 | - * @type string $root_slug The component root slug. Note that this value is generally unused if the |
|
47 | - * component has a root directory (the slug will be overridden by the |
|
48 | - * post_name of the directory page). Default: the slug of the directory page |
|
49 | - * if one is found, otherwise an empty string. |
|
50 | - * @type bool $has_directory Set to true if the component requires an associated WordPress page. |
|
51 | - * @type callable $notification_callback Optional. The callable function that formats the component's notifications. |
|
52 | - * @type string $search_term Optional. The placeholder text in the component directory search box. Eg, |
|
53 | - * 'Search Groups...'. |
|
54 | - * @type array $global_tables Optional. An array of database table names. |
|
55 | - * @type array $meta_tables Optional. An array of metadata table names. |
|
56 | - * } |
|
57 | - */ |
|
58 | - public function setup_globals( $args = array() ) { |
|
37 | + * Set up component global variables. |
|
38 | + * |
|
39 | + * @since 2.1.5 |
|
40 | + * |
|
41 | + * |
|
42 | + * @param array $args { |
|
43 | + * All values are optional. |
|
44 | + * @type string $slug The component slug. Used to construct certain URLs, such as 'friends' in |
|
45 | + * http://example.com/members/joe/friends/. Default: the value of $this->id. |
|
46 | + * @type string $root_slug The component root slug. Note that this value is generally unused if the |
|
47 | + * component has a root directory (the slug will be overridden by the |
|
48 | + * post_name of the directory page). Default: the slug of the directory page |
|
49 | + * if one is found, otherwise an empty string. |
|
50 | + * @type bool $has_directory Set to true if the component requires an associated WordPress page. |
|
51 | + * @type callable $notification_callback Optional. The callable function that formats the component's notifications. |
|
52 | + * @type string $search_term Optional. The placeholder text in the component directory search box. Eg, |
|
53 | + * 'Search Groups...'. |
|
54 | + * @type array $global_tables Optional. An array of database table names. |
|
55 | + * @type array $meta_tables Optional. An array of metadata table names. |
|
56 | + * } |
|
57 | + */ |
|
58 | + public function setup_globals( $args = array() ) { |
|
59 | 59 | parent::setup_globals( |
60 | 60 | array( |
61 | 61 | 'id' => 'getpaid', |
@@ -64,21 +64,21 @@ discard block |
||
64 | 64 | 'has_directory' => false |
65 | 65 | ) |
66 | 66 | ); |
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Set up component navigation. |
|
71 | - * |
|
72 | - * @since 2.1.5 |
|
73 | - * |
|
74 | - * @see BP_Component::setup_nav() for a description of arguments. |
|
75 | - * |
|
76 | - * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
|
77 | - * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
|
78 | - */ |
|
79 | - public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
80 | - |
|
81 | - // Abort if the integration is inactive. |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Set up component navigation. |
|
71 | + * |
|
72 | + * @since 2.1.5 |
|
73 | + * |
|
74 | + * @see BP_Component::setup_nav() for a description of arguments. |
|
75 | + * |
|
76 | + * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
|
77 | + * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
|
78 | + */ |
|
79 | + public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
80 | + |
|
81 | + // Abort if the integration is inactive. |
|
82 | 82 | if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) { |
83 | 83 | return; |
84 | 84 | } |
@@ -88,25 +88,25 @@ discard block |
||
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
91 | - // Determine user to use. |
|
92 | - $user_domain = bp_loggedin_user_domain(); |
|
93 | - $slug = 'getpaid'; |
|
94 | - $payments_link = trailingslashit( $user_domain . $slug ); |
|
95 | - |
|
96 | - // Add 'Payments' to the main navigation. |
|
97 | - $main_nav = array( |
|
98 | - 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
99 | - 'slug' => $slug, |
|
100 | - 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
101 | - 'screen_function' => array( $this, 'display_current_tab' ), |
|
102 | - 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
91 | + // Determine user to use. |
|
92 | + $user_domain = bp_loggedin_user_domain(); |
|
93 | + $slug = 'getpaid'; |
|
94 | + $payments_link = trailingslashit( $user_domain . $slug ); |
|
95 | + |
|
96 | + // Add 'Payments' to the main navigation. |
|
97 | + $main_nav = array( |
|
98 | + 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
99 | + 'slug' => $slug, |
|
100 | + 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
101 | + 'screen_function' => array( $this, 'display_current_tab' ), |
|
102 | + 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
103 | 103 | 'show_for_displayed_user' => false, |
104 | - 'item_css_id' => $this->id, |
|
105 | - 'parent_url' => $user_domain, |
|
106 | - 'parent_slug' => buddypress()->slug, |
|
107 | - ); |
|
104 | + 'item_css_id' => $this->id, |
|
105 | + 'parent_url' => $user_domain, |
|
106 | + 'parent_slug' => buddypress()->slug, |
|
107 | + ); |
|
108 | 108 | |
109 | - // Add the subnav items to the payments nav item if we are using a theme that supports this. |
|
109 | + // Add the subnav items to the payments nav item if we are using a theme that supports this. |
|
110 | 110 | foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) { |
111 | 111 | |
112 | 112 | $sub_nav[] = array( |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | 'parent_slug' => $slug, |
117 | 117 | 'position' => 10, |
118 | 118 | 'screen_function' => function() use ( $tab ) { |
119 | - $GLOBALS['getpaid_bp_current_tab'] = $tab; |
|
120 | - $this->display_current_tab(); |
|
119 | + $GLOBALS['getpaid_bp_current_tab'] = $tab; |
|
120 | + $this->display_current_tab(); |
|
121 | 121 | }, |
122 | 122 | 'show_for_displayed_user' => false, |
123 | 123 | 'item_css_id' => "getpaid-bp-$_slug", |
@@ -125,27 +125,27 @@ discard block |
||
125 | 125 | |
126 | 126 | } |
127 | 127 | |
128 | - parent::setup_nav( $main_nav, $sub_nav ); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Set up the component entries in the WordPress Admin Bar. |
|
133 | - * |
|
134 | - * @since 2.1.5 |
|
135 | - * |
|
136 | - * @see BP_Component::setup_nav() for a description of the $wp_admin_nav |
|
137 | - * parameter array. |
|
138 | - * |
|
139 | - * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
|
140 | - * description. |
|
141 | - */ |
|
142 | - public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
143 | - |
|
144 | - // Menus for logged in user. |
|
145 | - if ( is_user_logged_in() ) { |
|
128 | + parent::setup_nav( $main_nav, $sub_nav ); |
|
129 | + } |
|
146 | 130 | |
147 | - // Setup the logged in user variables. |
|
148 | - $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
131 | + /** |
|
132 | + * Set up the component entries in the WordPress Admin Bar. |
|
133 | + * |
|
134 | + * @since 2.1.5 |
|
135 | + * |
|
136 | + * @see BP_Component::setup_nav() for a description of the $wp_admin_nav |
|
137 | + * parameter array. |
|
138 | + * |
|
139 | + * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
|
140 | + * description. |
|
141 | + */ |
|
142 | + public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
143 | + |
|
144 | + // Menus for logged in user. |
|
145 | + if ( is_user_logged_in() ) { |
|
146 | + |
|
147 | + // Setup the logged in user variables. |
|
148 | + $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
149 | 149 | |
150 | 150 | // Add the "Payments" sub menu. |
151 | 151 | $wp_admin_nav[] = array( |
@@ -167,50 +167,50 @@ discard block |
||
167 | 167 | |
168 | 168 | } |
169 | 169 | |
170 | - } |
|
171 | - |
|
172 | - parent::setup_admin_bar( $wp_admin_nav ); |
|
173 | - } |
|
170 | + } |
|
174 | 171 | |
175 | - /** |
|
176 | - * Retrieves the current tab. |
|
177 | - * |
|
178 | - * @since 2.1.5 |
|
179 | - */ |
|
180 | - public function get_current_tab() { |
|
181 | - global $getpaid_bp_current_tab; |
|
172 | + parent::setup_admin_bar( $wp_admin_nav ); |
|
173 | + } |
|
182 | 174 | |
183 | - if ( empty( $getpaid_bp_current_tab ) ) { |
|
184 | - return array( |
|
185 | - 'label' => __( 'Invoices', 'invoicing' ), |
|
186 | - 'content' => '[wpinv_history]', |
|
187 | - 'icon' => 'fas fa-file-invoice', |
|
188 | - ); |
|
189 | - } |
|
175 | + /** |
|
176 | + * Retrieves the current tab. |
|
177 | + * |
|
178 | + * @since 2.1.5 |
|
179 | + */ |
|
180 | + public function get_current_tab() { |
|
181 | + global $getpaid_bp_current_tab; |
|
182 | + |
|
183 | + if ( empty( $getpaid_bp_current_tab ) ) { |
|
184 | + return array( |
|
185 | + 'label' => __( 'Invoices', 'invoicing' ), |
|
186 | + 'content' => '[wpinv_history]', |
|
187 | + 'icon' => 'fas fa-file-invoice', |
|
188 | + ); |
|
189 | + } |
|
190 | 190 | |
191 | - return $getpaid_bp_current_tab; |
|
192 | - } |
|
191 | + return $getpaid_bp_current_tab; |
|
192 | + } |
|
193 | 193 | |
194 | - /** |
|
195 | - * Displays the current tab. |
|
196 | - * |
|
197 | - * @since 2.1.5 |
|
198 | - */ |
|
199 | - public function display_current_tab() { |
|
194 | + /** |
|
195 | + * Displays the current tab. |
|
196 | + * |
|
197 | + * @since 2.1.5 |
|
198 | + */ |
|
199 | + public function display_current_tab() { |
|
200 | 200 | |
201 | - add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
202 | - $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
201 | + add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
202 | + $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
203 | 203 | |
204 | 204 | bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) ); |
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Handles the actual display of the current tab. |
|
209 | - * |
|
210 | - * @since 2.1.5 |
|
211 | - */ |
|
212 | - public function handle_display_current_tab() { |
|
213 | - echo getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
214 | - } |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Handles the actual display of the current tab. |
|
209 | + * |
|
210 | + * @since 2.1.5 |
|
211 | + */ |
|
212 | + public function handle_display_current_tab() { |
|
213 | + echo getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
214 | + } |
|
215 | 215 | |
216 | 216 | } |
@@ -19,16 +19,16 @@ discard block |
||
19 | 19 | |
20 | 20 | // Define constants. |
21 | 21 | if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
22 | + define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | if ( ! defined( 'WPINV_VERSION' ) ) { |
26 | - define( 'WPINV_VERSION', '2.5.12' ); |
|
26 | + define( 'WPINV_VERSION', '2.5.12' ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // Include the main Invoicing class. |
30 | 30 | if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
31 | + require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
44 | 44 | } |
45 | 45 | |
46 | - return $GLOBALS['invoicing']; |
|
46 | + return $GLOBALS['invoicing']; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -12,167 +12,167 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Discount { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission discounts. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $discounts = array(); |
|
15 | + /** |
|
16 | + * Submission discounts. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $discounts = array(); |
|
20 | + |
|
21 | + /** |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + * @param float $initial_total |
|
26 | + * @param float $recurring_total |
|
27 | + */ |
|
28 | + public function __construct( $submission, $initial_total, $recurring_total ) { |
|
29 | + |
|
30 | + // Process any existing invoice discounts. |
|
31 | + if ( $submission->has_invoice() ) { |
|
32 | + $this->discounts = $submission->get_invoice()->get_discounts(); |
|
33 | + } |
|
34 | + |
|
35 | + // Do we have a discount? |
|
36 | + $discount = $submission->get_field( 'discount' ); |
|
37 | + |
|
38 | + if ( empty( $discount ) ) { |
|
39 | + |
|
40 | + if ( isset( $this->discounts['discount_code'] ) ) { |
|
41 | + unset( $this->discounts['discount_code'] ); |
|
42 | + } |
|
43 | + |
|
44 | + return; |
|
45 | + } |
|
46 | + |
|
47 | + // Processes the discount code. |
|
48 | + $amount = max( $initial_total, $recurring_total ); |
|
49 | + $this->process_discount( $submission, $discount, $amount ); |
|
50 | + |
|
51 | + } |
|
20 | 52 | |
21 | 53 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - * @param float $initial_total |
|
26 | - * @param float $recurring_total |
|
27 | - */ |
|
28 | - public function __construct( $submission, $initial_total, $recurring_total ) { |
|
29 | - |
|
30 | - // Process any existing invoice discounts. |
|
31 | - if ( $submission->has_invoice() ) { |
|
32 | - $this->discounts = $submission->get_invoice()->get_discounts(); |
|
33 | - } |
|
34 | - |
|
35 | - // Do we have a discount? |
|
36 | - $discount = $submission->get_field( 'discount' ); |
|
37 | - |
|
38 | - if ( empty( $discount ) ) { |
|
39 | - |
|
40 | - if ( isset( $this->discounts['discount_code'] ) ) { |
|
41 | - unset( $this->discounts['discount_code'] ); |
|
42 | - } |
|
43 | - |
|
44 | - return; |
|
45 | - } |
|
46 | - |
|
47 | - // Processes the discount code. |
|
48 | - $amount = max( $initial_total, $recurring_total ); |
|
49 | - $this->process_discount( $submission, $discount, $amount ); |
|
50 | - |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Processes a submission discount. |
|
55 | - * |
|
56 | - * @param GetPaid_Payment_Form_Submission $submission |
|
57 | - * @param string $discount |
|
58 | - * @param float $amount |
|
59 | - */ |
|
60 | - public function process_discount( $submission, $discount, $amount ) { |
|
61 | - |
|
62 | - // Fetch the discount. |
|
63 | - $discount = new WPInv_Discount( $discount ); |
|
64 | - |
|
65 | - // Ensure it is active. |
|
54 | + * Processes a submission discount. |
|
55 | + * |
|
56 | + * @param GetPaid_Payment_Form_Submission $submission |
|
57 | + * @param string $discount |
|
58 | + * @param float $amount |
|
59 | + */ |
|
60 | + public function process_discount( $submission, $discount, $amount ) { |
|
61 | + |
|
62 | + // Fetch the discount. |
|
63 | + $discount = new WPInv_Discount( $discount ); |
|
64 | + |
|
65 | + // Ensure it is active. |
|
66 | 66 | if ( ! $this->is_discount_active( $discount ) ) { |
67 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
68 | - } |
|
69 | - |
|
70 | - // Required items. |
|
71 | - if ( ! $discount->is_required_items_met( array_keys( $submission->get_items() ) ) ) { |
|
72 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You are not allowed to use this discount code.', 'invoicing' ) ); |
|
73 | - } |
|
74 | - |
|
75 | - // Exceeded limit. |
|
76 | - if ( $discount->has_exceeded_limit() ) { |
|
77 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'This discount code has been used up', 'invoicing' ) ); |
|
78 | - } |
|
79 | - |
|
80 | - // Validate usages. |
|
81 | - $this->validate_single_use_discount( $submission, $discount ); |
|
82 | - |
|
83 | - // Validate amount. |
|
84 | - $this->validate_discount_amount( $submission, $discount, $amount ); |
|
85 | - |
|
86 | - // Save the discount. |
|
87 | - $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Validates a single use discount. |
|
92 | - * |
|
93 | - * @param WPInv_Discount $discount |
|
94 | - * @return bool |
|
95 | - */ |
|
96 | - public function is_discount_active( $discount ) { |
|
97 | - return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Returns a user's id or email. |
|
102 | - * |
|
103 | - * @param string $email |
|
104 | - * @return int|string|false |
|
105 | - */ |
|
106 | - public function get_user_id_or_email( $email ) { |
|
107 | - |
|
108 | - if ( is_user_logged_in() ) { |
|
109 | - return get_current_user_id(); |
|
110 | - } |
|
111 | - |
|
112 | - return empty( $email ) ? false : sanitize_email( $email ); |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Validates a single use discount. |
|
117 | - * |
|
118 | - * @param GetPaid_Payment_Form_Submission $submission |
|
119 | - * @param WPInv_Discount $discount |
|
120 | - */ |
|
121 | - public function validate_single_use_discount( $submission, $discount ) { |
|
122 | - |
|
123 | - // Abort if it is not a single use discount. |
|
124 | - if ( ! $discount->is_single_use() ) { |
|
125 | - return; |
|
126 | - } |
|
127 | - |
|
128 | - // Ensure there is a valid billing email. |
|
129 | - $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
130 | - |
|
131 | - if ( empty( $user ) ) { |
|
132 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
133 | - } |
|
134 | - |
|
135 | - // Has the user used this discount code before? |
|
136 | - if ( ! $discount->is_valid_for_user( $user ) ) { |
|
137 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You have already used this discount', 'invoicing' ) ); |
|
138 | - } |
|
139 | - |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Validates the discount's amount. |
|
144 | - * |
|
145 | - * @param GetPaid_Payment_Form_Submission $submission |
|
146 | - * @param WPInv_Discount $discount |
|
147 | - * @param float $amount |
|
148 | - */ |
|
149 | - public function validate_discount_amount( $submission, $discount, $amount ) { |
|
150 | - |
|
151 | - // Validate minimum amount. |
|
152 | - if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
153 | - $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
154 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
155 | - } |
|
156 | - |
|
157 | - // Validate the maximum amount. |
|
158 | - if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
159 | - $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
160 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
161 | - } |
|
162 | - |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Calculates the discount code's amount. |
|
167 | - * |
|
168 | - * Ensure that the discount exists and has been validated before calling this method. |
|
169 | - * |
|
170 | - * @param GetPaid_Payment_Form_Submission $submission |
|
171 | - * @param WPInv_Discount $discount |
|
172 | - * @return array |
|
173 | - */ |
|
174 | - public function calculate_discount( $submission, $discount ) { |
|
175 | - return getpaid_calculate_invoice_discount( $submission, $discount ); |
|
176 | - } |
|
67 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
68 | + } |
|
69 | + |
|
70 | + // Required items. |
|
71 | + if ( ! $discount->is_required_items_met( array_keys( $submission->get_items() ) ) ) { |
|
72 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You are not allowed to use this discount code.', 'invoicing' ) ); |
|
73 | + } |
|
74 | + |
|
75 | + // Exceeded limit. |
|
76 | + if ( $discount->has_exceeded_limit() ) { |
|
77 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'This discount code has been used up', 'invoicing' ) ); |
|
78 | + } |
|
79 | + |
|
80 | + // Validate usages. |
|
81 | + $this->validate_single_use_discount( $submission, $discount ); |
|
82 | + |
|
83 | + // Validate amount. |
|
84 | + $this->validate_discount_amount( $submission, $discount, $amount ); |
|
85 | + |
|
86 | + // Save the discount. |
|
87 | + $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Validates a single use discount. |
|
92 | + * |
|
93 | + * @param WPInv_Discount $discount |
|
94 | + * @return bool |
|
95 | + */ |
|
96 | + public function is_discount_active( $discount ) { |
|
97 | + return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Returns a user's id or email. |
|
102 | + * |
|
103 | + * @param string $email |
|
104 | + * @return int|string|false |
|
105 | + */ |
|
106 | + public function get_user_id_or_email( $email ) { |
|
107 | + |
|
108 | + if ( is_user_logged_in() ) { |
|
109 | + return get_current_user_id(); |
|
110 | + } |
|
111 | + |
|
112 | + return empty( $email ) ? false : sanitize_email( $email ); |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Validates a single use discount. |
|
117 | + * |
|
118 | + * @param GetPaid_Payment_Form_Submission $submission |
|
119 | + * @param WPInv_Discount $discount |
|
120 | + */ |
|
121 | + public function validate_single_use_discount( $submission, $discount ) { |
|
122 | + |
|
123 | + // Abort if it is not a single use discount. |
|
124 | + if ( ! $discount->is_single_use() ) { |
|
125 | + return; |
|
126 | + } |
|
127 | + |
|
128 | + // Ensure there is a valid billing email. |
|
129 | + $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
130 | + |
|
131 | + if ( empty( $user ) ) { |
|
132 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
133 | + } |
|
134 | + |
|
135 | + // Has the user used this discount code before? |
|
136 | + if ( ! $discount->is_valid_for_user( $user ) ) { |
|
137 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You have already used this discount', 'invoicing' ) ); |
|
138 | + } |
|
139 | + |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Validates the discount's amount. |
|
144 | + * |
|
145 | + * @param GetPaid_Payment_Form_Submission $submission |
|
146 | + * @param WPInv_Discount $discount |
|
147 | + * @param float $amount |
|
148 | + */ |
|
149 | + public function validate_discount_amount( $submission, $discount, $amount ) { |
|
150 | + |
|
151 | + // Validate minimum amount. |
|
152 | + if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
153 | + $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
154 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
155 | + } |
|
156 | + |
|
157 | + // Validate the maximum amount. |
|
158 | + if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
159 | + $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
160 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
161 | + } |
|
162 | + |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Calculates the discount code's amount. |
|
167 | + * |
|
168 | + * Ensure that the discount exists and has been validated before calling this method. |
|
169 | + * |
|
170 | + * @param GetPaid_Payment_Form_Submission $submission |
|
171 | + * @param WPInv_Discount $discount |
|
172 | + * @return array |
|
173 | + */ |
|
174 | + public function calculate_discount( $submission, $discount ) { |
|
175 | + return getpaid_calculate_invoice_discount( $submission, $discount ); |
|
176 | + } |
|
177 | 177 | |
178 | 178 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Discount_Details { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the discount. |
@@ -396,35 +396,35 @@ discard block |
||
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
399 | - * Save meta box data. |
|
400 | - * |
|
401 | - * @param int $post_id |
|
402 | - */ |
|
403 | - public static function save( $post_id ) { |
|
399 | + * Save meta box data. |
|
400 | + * |
|
401 | + * @param int $post_id |
|
402 | + */ |
|
403 | + public static function save( $post_id ) { |
|
404 | 404 | |
405 | 405 | // Prepare the discount. |
406 | 406 | $discount = new WPInv_Discount( $post_id ); |
407 | 407 | |
408 | 408 | // Load new data. |
409 | 409 | $discount->set_props( |
410 | - array( |
|
411 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
412 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
413 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
414 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
415 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
410 | + array( |
|
411 | + 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
412 | + 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
413 | + 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
414 | + 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
415 | + 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
416 | 416 | 'type' => isset( $_POST['wpinv_discount_type'] ) ? wpinv_clean( $_POST['wpinv_discount_type'] ) : null, |
417 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
418 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
419 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
417 | + 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
418 | + 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
419 | + 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
420 | 420 | 'required_items' => isset( $_POST['wpinv_discount_required_items'] ) ? wpinv_clean( $_POST['wpinv_discount_required_items'] ) : array(), |
421 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
422 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
423 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
424 | - ) |
|
421 | + 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
422 | + 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
423 | + 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
424 | + ) |
|
425 | 425 | ); |
426 | 426 | |
427 | - $discount->save(); |
|
428 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
429 | - } |
|
427 | + $discount->save(); |
|
428 | + do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
429 | + } |
|
430 | 430 | } |
@@ -13,177 +13,177 @@ |
||
13 | 13 | |
14 | 14 | return array( |
15 | 15 | |
16 | - 'id' => array( |
|
17 | - 'description' => __( 'Unique identifier for the discount.', 'invoicing' ), |
|
18 | - 'type' => 'integer', |
|
19 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
20 | - 'readonly' => true, |
|
21 | - ), |
|
22 | - |
|
23 | - 'status' => array( |
|
24 | - 'description' => __( 'A named status for the discount.', 'invoicing' ), |
|
25 | - 'type' => 'string', |
|
26 | - 'enum' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
27 | - 'default' => 'draft', |
|
28 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
29 | - ), |
|
30 | - |
|
31 | - 'version' => array( |
|
32 | - 'description' => __( 'Plugin version when the discount was created.', 'invoicing' ), |
|
33 | - 'type' => 'string', |
|
34 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
35 | - 'readonly' => true, |
|
36 | - ), |
|
37 | - |
|
38 | - 'date_created' => array( |
|
39 | - 'description' => __( "The date the discount was created, in the site's timezone.", 'invoicing' ), |
|
40 | - 'type' => 'string', |
|
41 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
42 | - ), |
|
43 | - |
|
44 | - 'date_created_gmt' => array( |
|
45 | - 'description' => __( 'The GMT date the discount was created.', 'invoicing' ), |
|
46 | - 'type' => 'string', |
|
47 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
48 | - 'readonly' => true, |
|
49 | - ), |
|
50 | - |
|
51 | - 'date_modified' => array( |
|
52 | - 'description' => __( "The date the discount was last modified, in the site's timezone.", 'invoicing' ), |
|
53 | - 'type' => 'string', |
|
54 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
55 | - 'readonly' => true, |
|
56 | - ), |
|
57 | - |
|
58 | - 'date_modified_gmt' => array( |
|
59 | - 'description' => __( 'The GMT date the discount was last modified.', 'invoicing' ), |
|
60 | - 'type' => 'string', |
|
61 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
62 | - 'readonly' => true, |
|
63 | - ), |
|
64 | - |
|
65 | - 'name' => array( |
|
66 | - 'description' => __( 'The discount name.', 'invoicing' ), |
|
67 | - 'type' => 'string', |
|
68 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
69 | - ), |
|
70 | - |
|
71 | - 'description' => array( |
|
72 | - 'description' => __( 'A description of what the discount is all about.', 'invoicing' ), |
|
73 | - 'type' => 'string', |
|
74 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
75 | - ), |
|
76 | - |
|
77 | - 'code' => array( |
|
78 | - 'description' => __( 'The discount code.', 'invoicing' ), |
|
79 | - 'type' => 'string', |
|
80 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
81 | - 'required' => true, |
|
82 | - ), |
|
83 | - |
|
84 | - 'type' => array( |
|
85 | - 'description' => __( 'The type of discount.', 'invoicing' ), |
|
86 | - 'type' => 'string', |
|
87 | - 'enum' => array_keys( wpinv_get_discount_types() ), |
|
88 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
89 | - 'default' => 'percent', |
|
90 | - ), |
|
91 | - |
|
92 | - 'amount' => array( |
|
93 | - 'description' => __( 'The discount value.', 'invoicing' ), |
|
94 | - 'type' => 'number', |
|
95 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
96 | - 'required' => true, |
|
97 | - ), |
|
98 | - |
|
99 | - 'formatted_amount' => array( |
|
100 | - 'description' => __( 'The formatted discount value.', 'invoicing' ), |
|
101 | - 'type' => 'string', |
|
102 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
103 | - 'readonly' => true, |
|
104 | - ), |
|
105 | - |
|
106 | - 'uses' => array( |
|
107 | - 'description' => __( 'The number of times the discount has been used.', 'invoicing' ), |
|
108 | - 'type' => 'integer', |
|
109 | - 'context' => array( 'view', 'embed' ), |
|
110 | - 'readonly' => true, |
|
111 | - ), |
|
112 | - |
|
113 | - 'max_uses' => array( |
|
114 | - 'description' => __( 'The maximum number of times the discount can be used.', 'invoicing' ), |
|
115 | - 'type' => 'integer', |
|
116 | - 'context' => array( 'view', 'edit' ), |
|
117 | - ), |
|
118 | - |
|
119 | - 'usage' => array( |
|
120 | - 'description' => __( "The discount's usage, i.e uses / max uses.", 'invoicing' ), |
|
121 | - 'type' => 'string', |
|
122 | - 'context' => array( 'view', 'embed' ), |
|
123 | - 'readonly' => true, |
|
124 | - ), |
|
125 | - |
|
126 | - 'is_single_use' => array( |
|
127 | - 'description' => __( 'Whether or not the discount can only be used once per user.', 'invoicing' ), |
|
128 | - 'type' => 'boolean', |
|
129 | - 'context' => array( 'view', 'edit' ), |
|
130 | - ), |
|
131 | - |
|
132 | - 'is_recurring' => array( |
|
133 | - 'description' => __( 'Whether or not the discount applies to the initial payment only or all recurring payments.', 'invoicing' ), |
|
134 | - 'type' => 'boolean', |
|
135 | - 'context' => array( 'view', 'edit' ), |
|
136 | - ), |
|
137 | - |
|
138 | - 'start_date' => array( |
|
139 | - 'description' => __( 'The start date for the discount in the format of yyyy-mm-dd hh:mm:ss. If provided, the discount can only be used after or on this date.', 'invoicing' ), |
|
140 | - 'type' => 'string', |
|
141 | - 'context' => array( 'view', 'edit' ), |
|
142 | - ), |
|
143 | - |
|
144 | - 'end_date' => array( |
|
145 | - 'description' => __( 'The expiration date for the discount.', 'invoicing' ), |
|
146 | - 'type' => 'string', |
|
147 | - 'context' => array( 'view', 'edit' ), |
|
148 | - ), |
|
149 | - |
|
150 | - 'allowed_items' => array( |
|
151 | - 'description' => __( 'Items which are allowed to use this discount. Leave blank to enable for all items.', 'invoicing' ), |
|
152 | - 'type' => 'array', |
|
153 | - 'context' => array( 'view', 'edit' ), |
|
154 | - 'items' => array( |
|
155 | - 'type' => 'integer' |
|
156 | - ) |
|
157 | - ), |
|
158 | - |
|
159 | - 'excluded_items' => array( |
|
160 | - 'description' => __( 'Items which are NOT allowed to use this discount.', 'invoicing' ), |
|
161 | - 'type' => 'array', |
|
162 | - 'context' => array( 'view', 'edit' ), |
|
163 | - 'items' => array( |
|
164 | - 'type' => 'integer' |
|
165 | - ) |
|
166 | - ), |
|
167 | - |
|
168 | - 'required_items' => array( |
|
169 | - 'description' => __( 'Items which are required to be in the cart before using this discount.', 'invoicing' ), |
|
170 | - 'type' => 'array', |
|
171 | - 'context' => array( 'view', 'edit' ), |
|
172 | - 'items' => array( |
|
173 | - 'type' => 'integer' |
|
174 | - ) |
|
175 | - ), |
|
176 | - |
|
177 | - 'minimum_total' => array( |
|
178 | - 'description' => __( 'The minimum total needed to use this invoice.', 'invoicing' ), |
|
179 | - 'type' => 'number', |
|
180 | - 'context' => array( 'view', 'edit' ), |
|
181 | - ), |
|
182 | - |
|
183 | - 'maximum_total' => array( |
|
184 | - 'description' => __( 'The maximum total needed to use this invoice.', 'invoicing' ), |
|
185 | - 'type' => 'number', |
|
186 | - 'context' => array( 'view', 'edit' ), |
|
187 | - ), |
|
16 | + 'id' => array( |
|
17 | + 'description' => __( 'Unique identifier for the discount.', 'invoicing' ), |
|
18 | + 'type' => 'integer', |
|
19 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
20 | + 'readonly' => true, |
|
21 | + ), |
|
22 | + |
|
23 | + 'status' => array( |
|
24 | + 'description' => __( 'A named status for the discount.', 'invoicing' ), |
|
25 | + 'type' => 'string', |
|
26 | + 'enum' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
27 | + 'default' => 'draft', |
|
28 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
29 | + ), |
|
30 | + |
|
31 | + 'version' => array( |
|
32 | + 'description' => __( 'Plugin version when the discount was created.', 'invoicing' ), |
|
33 | + 'type' => 'string', |
|
34 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
35 | + 'readonly' => true, |
|
36 | + ), |
|
37 | + |
|
38 | + 'date_created' => array( |
|
39 | + 'description' => __( "The date the discount was created, in the site's timezone.", 'invoicing' ), |
|
40 | + 'type' => 'string', |
|
41 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
42 | + ), |
|
43 | + |
|
44 | + 'date_created_gmt' => array( |
|
45 | + 'description' => __( 'The GMT date the discount was created.', 'invoicing' ), |
|
46 | + 'type' => 'string', |
|
47 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
48 | + 'readonly' => true, |
|
49 | + ), |
|
50 | + |
|
51 | + 'date_modified' => array( |
|
52 | + 'description' => __( "The date the discount was last modified, in the site's timezone.", 'invoicing' ), |
|
53 | + 'type' => 'string', |
|
54 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
55 | + 'readonly' => true, |
|
56 | + ), |
|
57 | + |
|
58 | + 'date_modified_gmt' => array( |
|
59 | + 'description' => __( 'The GMT date the discount was last modified.', 'invoicing' ), |
|
60 | + 'type' => 'string', |
|
61 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
62 | + 'readonly' => true, |
|
63 | + ), |
|
64 | + |
|
65 | + 'name' => array( |
|
66 | + 'description' => __( 'The discount name.', 'invoicing' ), |
|
67 | + 'type' => 'string', |
|
68 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
69 | + ), |
|
70 | + |
|
71 | + 'description' => array( |
|
72 | + 'description' => __( 'A description of what the discount is all about.', 'invoicing' ), |
|
73 | + 'type' => 'string', |
|
74 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
75 | + ), |
|
76 | + |
|
77 | + 'code' => array( |
|
78 | + 'description' => __( 'The discount code.', 'invoicing' ), |
|
79 | + 'type' => 'string', |
|
80 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
81 | + 'required' => true, |
|
82 | + ), |
|
83 | + |
|
84 | + 'type' => array( |
|
85 | + 'description' => __( 'The type of discount.', 'invoicing' ), |
|
86 | + 'type' => 'string', |
|
87 | + 'enum' => array_keys( wpinv_get_discount_types() ), |
|
88 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
89 | + 'default' => 'percent', |
|
90 | + ), |
|
91 | + |
|
92 | + 'amount' => array( |
|
93 | + 'description' => __( 'The discount value.', 'invoicing' ), |
|
94 | + 'type' => 'number', |
|
95 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
96 | + 'required' => true, |
|
97 | + ), |
|
98 | + |
|
99 | + 'formatted_amount' => array( |
|
100 | + 'description' => __( 'The formatted discount value.', 'invoicing' ), |
|
101 | + 'type' => 'string', |
|
102 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
103 | + 'readonly' => true, |
|
104 | + ), |
|
105 | + |
|
106 | + 'uses' => array( |
|
107 | + 'description' => __( 'The number of times the discount has been used.', 'invoicing' ), |
|
108 | + 'type' => 'integer', |
|
109 | + 'context' => array( 'view', 'embed' ), |
|
110 | + 'readonly' => true, |
|
111 | + ), |
|
112 | + |
|
113 | + 'max_uses' => array( |
|
114 | + 'description' => __( 'The maximum number of times the discount can be used.', 'invoicing' ), |
|
115 | + 'type' => 'integer', |
|
116 | + 'context' => array( 'view', 'edit' ), |
|
117 | + ), |
|
118 | + |
|
119 | + 'usage' => array( |
|
120 | + 'description' => __( "The discount's usage, i.e uses / max uses.", 'invoicing' ), |
|
121 | + 'type' => 'string', |
|
122 | + 'context' => array( 'view', 'embed' ), |
|
123 | + 'readonly' => true, |
|
124 | + ), |
|
125 | + |
|
126 | + 'is_single_use' => array( |
|
127 | + 'description' => __( 'Whether or not the discount can only be used once per user.', 'invoicing' ), |
|
128 | + 'type' => 'boolean', |
|
129 | + 'context' => array( 'view', 'edit' ), |
|
130 | + ), |
|
131 | + |
|
132 | + 'is_recurring' => array( |
|
133 | + 'description' => __( 'Whether or not the discount applies to the initial payment only or all recurring payments.', 'invoicing' ), |
|
134 | + 'type' => 'boolean', |
|
135 | + 'context' => array( 'view', 'edit' ), |
|
136 | + ), |
|
137 | + |
|
138 | + 'start_date' => array( |
|
139 | + 'description' => __( 'The start date for the discount in the format of yyyy-mm-dd hh:mm:ss. If provided, the discount can only be used after or on this date.', 'invoicing' ), |
|
140 | + 'type' => 'string', |
|
141 | + 'context' => array( 'view', 'edit' ), |
|
142 | + ), |
|
143 | + |
|
144 | + 'end_date' => array( |
|
145 | + 'description' => __( 'The expiration date for the discount.', 'invoicing' ), |
|
146 | + 'type' => 'string', |
|
147 | + 'context' => array( 'view', 'edit' ), |
|
148 | + ), |
|
149 | + |
|
150 | + 'allowed_items' => array( |
|
151 | + 'description' => __( 'Items which are allowed to use this discount. Leave blank to enable for all items.', 'invoicing' ), |
|
152 | + 'type' => 'array', |
|
153 | + 'context' => array( 'view', 'edit' ), |
|
154 | + 'items' => array( |
|
155 | + 'type' => 'integer' |
|
156 | + ) |
|
157 | + ), |
|
158 | + |
|
159 | + 'excluded_items' => array( |
|
160 | + 'description' => __( 'Items which are NOT allowed to use this discount.', 'invoicing' ), |
|
161 | + 'type' => 'array', |
|
162 | + 'context' => array( 'view', 'edit' ), |
|
163 | + 'items' => array( |
|
164 | + 'type' => 'integer' |
|
165 | + ) |
|
166 | + ), |
|
167 | + |
|
168 | + 'required_items' => array( |
|
169 | + 'description' => __( 'Items which are required to be in the cart before using this discount.', 'invoicing' ), |
|
170 | + 'type' => 'array', |
|
171 | + 'context' => array( 'view', 'edit' ), |
|
172 | + 'items' => array( |
|
173 | + 'type' => 'integer' |
|
174 | + ) |
|
175 | + ), |
|
176 | + |
|
177 | + 'minimum_total' => array( |
|
178 | + 'description' => __( 'The minimum total needed to use this invoice.', 'invoicing' ), |
|
179 | + 'type' => 'number', |
|
180 | + 'context' => array( 'view', 'edit' ), |
|
181 | + ), |
|
182 | + |
|
183 | + 'maximum_total' => array( |
|
184 | + 'description' => __( 'The maximum total needed to use this invoice.', 'invoicing' ), |
|
185 | + 'type' => 'number', |
|
186 | + 'context' => array( 'view', 'edit' ), |
|
187 | + ), |
|
188 | 188 | |
189 | 189 | ); |
@@ -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,144 +59,144 @@ 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 | - } |
|
98 | - |
|
99 | - } elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) { |
|
100 | - $this->set_id( $discount ); |
|
101 | - } else { |
|
102 | - $this->set_object_read( true ); |
|
103 | - } |
|
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 | + |
|
99 | + } elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) { |
|
100 | + $this->set_id( $discount ); |
|
101 | + } else { |
|
102 | + $this->set_object_read( true ); |
|
103 | + } |
|
104 | 104 | |
105 | 105 | // Load the datastore. |
106 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
106 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
107 | 107 | |
108 | - if ( $this->get_id() > 0 ) { |
|
108 | + if ( $this->get_id() > 0 ) { |
|
109 | 109 | $this->post = get_post( $this->get_id() ); |
110 | 110 | $this->ID = $this->get_id(); |
111 | - $this->data_store->read( $this ); |
|
111 | + $this->data_store->read( $this ); |
|
112 | + } |
|
113 | + |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Fetch a discount from the db/cache |
|
118 | + * |
|
119 | + * |
|
120 | + * @static |
|
121 | + * @param string $field The field to query against: 'ID', 'discount_code' |
|
122 | + * @param string|int $value The field value |
|
123 | + * @deprecated |
|
124 | + * @since 1.0.15 |
|
125 | + * @return array|bool array of discount details on success. False otherwise. |
|
126 | + */ |
|
127 | + public static function get_data_by( $field, $value ) { |
|
128 | + |
|
129 | + if ( 'id' == strtolower( $field ) ) { |
|
130 | + // Make sure the value is numeric to avoid casting objects, for example, |
|
131 | + // to int 1. |
|
132 | + if ( ! is_numeric( $value ) ) |
|
133 | + return false; |
|
134 | + $value = intval( $value ); |
|
135 | + if ( $value < 1 ) |
|
136 | + return false; |
|
137 | + } |
|
138 | + |
|
139 | + if ( ! $value || ! is_string( $field ) ) { |
|
140 | + return false; |
|
141 | + } |
|
142 | + |
|
143 | + $field = trim( $field ); |
|
144 | + |
|
145 | + // prepare query args |
|
146 | + switch ( strtolower( $field ) ) { |
|
147 | + case 'id': |
|
148 | + $discount_id = $value; |
|
149 | + $args = array( 'include' => array( $value ) ); |
|
150 | + break; |
|
151 | + case 'discount_code': |
|
152 | + case 'code': |
|
153 | + $value = trim( $value ); |
|
154 | + $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' ); |
|
155 | + $args = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value ); |
|
156 | + break; |
|
157 | + case 'name': |
|
158 | + $discount_id = 0; |
|
159 | + $args = array( 'name' => trim( $value ) ); |
|
160 | + break; |
|
161 | + default: |
|
162 | + $args = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value ); |
|
163 | + if ( ! is_array( $args ) ) { |
|
164 | + return apply_filters( "wpinv_discount_get_data_by_$field", false, $value ); |
|
165 | + } |
|
166 | + |
|
167 | + } |
|
168 | + |
|
169 | + // Check if there is a cached value. |
|
170 | + if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) { |
|
171 | + return $discount; |
|
172 | + } |
|
173 | + |
|
174 | + $args = array_merge( |
|
175 | + $args, |
|
176 | + array( |
|
177 | + 'post_type' => 'wpi_discount', |
|
178 | + 'posts_per_page' => 1, |
|
179 | + 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
180 | + ) |
|
181 | + ); |
|
182 | + |
|
183 | + $discount = get_posts( $args ); |
|
184 | + |
|
185 | + if( empty( $discount ) ) { |
|
186 | + return false; |
|
112 | 187 | } |
113 | 188 | |
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Fetch a discount from the db/cache |
|
118 | - * |
|
119 | - * |
|
120 | - * @static |
|
121 | - * @param string $field The field to query against: 'ID', 'discount_code' |
|
122 | - * @param string|int $value The field value |
|
123 | - * @deprecated |
|
124 | - * @since 1.0.15 |
|
125 | - * @return array|bool array of discount details on success. False otherwise. |
|
126 | - */ |
|
127 | - public static function get_data_by( $field, $value ) { |
|
128 | - |
|
129 | - if ( 'id' == strtolower( $field ) ) { |
|
130 | - // Make sure the value is numeric to avoid casting objects, for example, |
|
131 | - // to int 1. |
|
132 | - if ( ! is_numeric( $value ) ) |
|
133 | - return false; |
|
134 | - $value = intval( $value ); |
|
135 | - if ( $value < 1 ) |
|
136 | - return false; |
|
137 | - } |
|
138 | - |
|
139 | - if ( ! $value || ! is_string( $field ) ) { |
|
140 | - return false; |
|
141 | - } |
|
142 | - |
|
143 | - $field = trim( $field ); |
|
144 | - |
|
145 | - // prepare query args |
|
146 | - switch ( strtolower( $field ) ) { |
|
147 | - case 'id': |
|
148 | - $discount_id = $value; |
|
149 | - $args = array( 'include' => array( $value ) ); |
|
150 | - break; |
|
151 | - case 'discount_code': |
|
152 | - case 'code': |
|
153 | - $value = trim( $value ); |
|
154 | - $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' ); |
|
155 | - $args = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value ); |
|
156 | - break; |
|
157 | - case 'name': |
|
158 | - $discount_id = 0; |
|
159 | - $args = array( 'name' => trim( $value ) ); |
|
160 | - break; |
|
161 | - default: |
|
162 | - $args = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value ); |
|
163 | - if ( ! is_array( $args ) ) { |
|
164 | - return apply_filters( "wpinv_discount_get_data_by_$field", false, $value ); |
|
165 | - } |
|
166 | - |
|
167 | - } |
|
168 | - |
|
169 | - // Check if there is a cached value. |
|
170 | - if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) { |
|
171 | - return $discount; |
|
172 | - } |
|
173 | - |
|
174 | - $args = array_merge( |
|
175 | - $args, |
|
176 | - array( |
|
177 | - 'post_type' => 'wpi_discount', |
|
178 | - 'posts_per_page' => 1, |
|
179 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
180 | - ) |
|
181 | - ); |
|
182 | - |
|
183 | - $discount = get_posts( $args ); |
|
184 | - |
|
185 | - if( empty( $discount ) ) { |
|
186 | - return false; |
|
187 | - } |
|
188 | - |
|
189 | - $discount = $discount[0]; |
|
190 | - |
|
191 | - // Prepare the return data. |
|
192 | - $return = array( |
|
189 | + $discount = $discount[0]; |
|
190 | + |
|
191 | + // Prepare the return data. |
|
192 | + $return = array( |
|
193 | 193 | 'ID' => $discount->ID, |
194 | 194 | 'code' => get_post_meta( $discount->ID, '_wpi_discount_code', true ), |
195 | 195 | 'amount' => get_post_meta( $discount->ID, '_wpi_discount_amount', true ), |
196 | 196 | 'date_created' => $discount->post_date, |
197 | - 'date_modified' => $discount->post_modified, |
|
198 | - 'status' => $discount->post_status, |
|
199 | - 'start' => get_post_meta( $discount->ID, '_wpi_discount_start', true ), |
|
197 | + 'date_modified' => $discount->post_modified, |
|
198 | + 'status' => $discount->post_status, |
|
199 | + 'start' => get_post_meta( $discount->ID, '_wpi_discount_start', true ), |
|
200 | 200 | 'expiration' => get_post_meta( $discount->ID, '_wpi_discount_expiration', true ), |
201 | 201 | 'type' => get_post_meta( $discount->ID, '_wpi_discount_type', true ), |
202 | 202 | 'description' => $discount->post_excerpt, |
@@ -204,84 +204,84 @@ discard block |
||
204 | 204 | 'is_single_use' => get_post_meta( $discount->ID, '_wpi_discount_is_single_use', true ), |
205 | 205 | 'items' => get_post_meta( $discount->ID, '_wpi_discount_items', true ), |
206 | 206 | 'excluded_items' => get_post_meta( $discount->ID, '_wpi_discount_excluded_items', true ), |
207 | - 'required_items' => get_post_meta( $discount->ID, '_wpi_discount_required_items', true ), |
|
207 | + 'required_items' => get_post_meta( $discount->ID, '_wpi_discount_required_items', true ), |
|
208 | 208 | 'max_uses' => get_post_meta( $discount->ID, '_wpi_discount_max_uses', true ), |
209 | 209 | 'is_recurring' => get_post_meta( $discount->ID, '_wpi_discount_is_recurring', true ), |
210 | 210 | 'min_total' => get_post_meta( $discount->ID, '_wpi_discount_min_total', true ), |
211 | 211 | 'max_total' => get_post_meta( $discount->ID, '_wpi_discount_max_total', true ), |
212 | 212 | ); |
213 | 213 | |
214 | - $return = apply_filters( 'wpinv_discount_properties', $return ); |
|
215 | - |
|
216 | - // Update the cache with our data |
|
217 | - wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' ); |
|
218 | - wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' ); |
|
219 | - |
|
220 | - return $return; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Given a discount code, it returns a discount id. |
|
225 | - * |
|
226 | - * |
|
227 | - * @static |
|
228 | - * @param string $discount_code |
|
229 | - * @since 1.0.15 |
|
230 | - * @return int |
|
231 | - */ |
|
232 | - public static function get_discount_id_by_code( $discount_code ) { |
|
233 | - |
|
234 | - // Trim the code. |
|
235 | - $discount_code = trim( $discount_code ); |
|
236 | - |
|
237 | - // Ensure a value has been passed. |
|
238 | - if ( empty( $discount_code ) ) { |
|
239 | - return 0; |
|
240 | - } |
|
241 | - |
|
242 | - // Maybe retrieve from the cache. |
|
243 | - $discount_id = wp_cache_get( $discount_code, 'getpaid_discount_codes' ); |
|
244 | - if ( ! empty( $discount_id ) ) { |
|
245 | - return $discount_id; |
|
246 | - } |
|
247 | - |
|
248 | - // Fetch the first discount codes. |
|
249 | - $discounts = get_posts( |
|
250 | - array( |
|
251 | - 'meta_key' => '_wpi_discount_code', |
|
252 | - 'meta_value' => $discount_code, |
|
253 | - 'post_type' => 'wpi_discount', |
|
254 | - 'posts_per_page' => 1, |
|
255 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
256 | - 'fields' => 'ids', |
|
257 | - ) |
|
258 | - ); |
|
259 | - |
|
260 | - if ( empty( $discounts ) ) { |
|
261 | - return 0; |
|
262 | - } |
|
263 | - |
|
264 | - $discount_id = $discounts[0]; |
|
265 | - |
|
266 | - // Update the cache with our data |
|
267 | - wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' ); |
|
268 | - |
|
269 | - return $discount_id; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Magic method for checking the existence of a certain custom field. |
|
274 | - * |
|
275 | - * @since 1.0.15 |
|
276 | - * @access public |
|
277 | - * |
|
278 | - * @return bool Whether the given discount field is set. |
|
279 | - */ |
|
280 | - public function __isset( $key ){ |
|
281 | - return isset( $this->data[$key] ) || method_exists( $this, "get_$key"); |
|
282 | - } |
|
283 | - |
|
284 | - /* |
|
214 | + $return = apply_filters( 'wpinv_discount_properties', $return ); |
|
215 | + |
|
216 | + // Update the cache with our data |
|
217 | + wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' ); |
|
218 | + wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' ); |
|
219 | + |
|
220 | + return $return; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Given a discount code, it returns a discount id. |
|
225 | + * |
|
226 | + * |
|
227 | + * @static |
|
228 | + * @param string $discount_code |
|
229 | + * @since 1.0.15 |
|
230 | + * @return int |
|
231 | + */ |
|
232 | + public static function get_discount_id_by_code( $discount_code ) { |
|
233 | + |
|
234 | + // Trim the code. |
|
235 | + $discount_code = trim( $discount_code ); |
|
236 | + |
|
237 | + // Ensure a value has been passed. |
|
238 | + if ( empty( $discount_code ) ) { |
|
239 | + return 0; |
|
240 | + } |
|
241 | + |
|
242 | + // Maybe retrieve from the cache. |
|
243 | + $discount_id = wp_cache_get( $discount_code, 'getpaid_discount_codes' ); |
|
244 | + if ( ! empty( $discount_id ) ) { |
|
245 | + return $discount_id; |
|
246 | + } |
|
247 | + |
|
248 | + // Fetch the first discount codes. |
|
249 | + $discounts = get_posts( |
|
250 | + array( |
|
251 | + 'meta_key' => '_wpi_discount_code', |
|
252 | + 'meta_value' => $discount_code, |
|
253 | + 'post_type' => 'wpi_discount', |
|
254 | + 'posts_per_page' => 1, |
|
255 | + 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
256 | + 'fields' => 'ids', |
|
257 | + ) |
|
258 | + ); |
|
259 | + |
|
260 | + if ( empty( $discounts ) ) { |
|
261 | + return 0; |
|
262 | + } |
|
263 | + |
|
264 | + $discount_id = $discounts[0]; |
|
265 | + |
|
266 | + // Update the cache with our data |
|
267 | + wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' ); |
|
268 | + |
|
269 | + return $discount_id; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Magic method for checking the existence of a certain custom field. |
|
274 | + * |
|
275 | + * @since 1.0.15 |
|
276 | + * @access public |
|
277 | + * |
|
278 | + * @return bool Whether the given discount field is set. |
|
279 | + */ |
|
280 | + public function __isset( $key ){ |
|
281 | + return isset( $this->data[$key] ) || method_exists( $this, "get_$key"); |
|
282 | + } |
|
283 | + |
|
284 | + /* |
|
285 | 285 | |-------------------------------------------------------------------------- |
286 | 286 | | CRUD methods |
287 | 287 | |-------------------------------------------------------------------------- |
@@ -296,441 +296,441 @@ discard block |
||
296 | 296 | |-------------------------------------------------------------------------- |
297 | 297 | */ |
298 | 298 | |
299 | - /** |
|
300 | - * Get discount status. |
|
301 | - * |
|
302 | - * @since 1.0.19 |
|
303 | - * @param string $context View or edit context. |
|
304 | - * @return string |
|
305 | - */ |
|
306 | - public function get_status( $context = 'view' ) { |
|
307 | - return $this->get_prop( 'status', $context ); |
|
299 | + /** |
|
300 | + * Get discount status. |
|
301 | + * |
|
302 | + * @since 1.0.19 |
|
303 | + * @param string $context View or edit context. |
|
304 | + * @return string |
|
305 | + */ |
|
306 | + public function get_status( $context = 'view' ) { |
|
307 | + return $this->get_prop( 'status', $context ); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
311 | - * Get plugin version when the discount was created. |
|
312 | - * |
|
313 | - * @since 1.0.19 |
|
314 | - * @param string $context View or edit context. |
|
315 | - * @return string |
|
316 | - */ |
|
317 | - public function get_version( $context = 'view' ) { |
|
318 | - return $this->get_prop( 'version', $context ); |
|
311 | + * Get plugin version when the discount was created. |
|
312 | + * |
|
313 | + * @since 1.0.19 |
|
314 | + * @param string $context View or edit context. |
|
315 | + * @return string |
|
316 | + */ |
|
317 | + public function get_version( $context = 'view' ) { |
|
318 | + return $this->get_prop( 'version', $context ); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
322 | - * Get date when the discount was created. |
|
323 | - * |
|
324 | - * @since 1.0.19 |
|
325 | - * @param string $context View or edit context. |
|
326 | - * @return string |
|
327 | - */ |
|
328 | - public function get_date_created( $context = 'view' ) { |
|
329 | - return $this->get_prop( 'date_created', $context ); |
|
322 | + * Get date when the discount was created. |
|
323 | + * |
|
324 | + * @since 1.0.19 |
|
325 | + * @param string $context View or edit context. |
|
326 | + * @return string |
|
327 | + */ |
|
328 | + public function get_date_created( $context = 'view' ) { |
|
329 | + return $this->get_prop( 'date_created', $context ); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /** |
333 | - * Get GMT date when the discount was created. |
|
334 | - * |
|
335 | - * @since 1.0.19 |
|
336 | - * @param string $context View or edit context. |
|
337 | - * @return string |
|
338 | - */ |
|
339 | - public function get_date_created_gmt( $context = 'view' ) { |
|
333 | + * Get GMT date when the discount was created. |
|
334 | + * |
|
335 | + * @since 1.0.19 |
|
336 | + * @param string $context View or edit context. |
|
337 | + * @return string |
|
338 | + */ |
|
339 | + public function get_date_created_gmt( $context = 'view' ) { |
|
340 | 340 | $date = $this->get_date_created( $context ); |
341 | 341 | |
342 | 342 | if ( $date ) { |
343 | 343 | $date = get_gmt_from_date( $date ); |
344 | 344 | } |
345 | - return $date; |
|
345 | + return $date; |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
349 | - * Get date when the discount was last modified. |
|
350 | - * |
|
351 | - * @since 1.0.19 |
|
352 | - * @param string $context View or edit context. |
|
353 | - * @return string |
|
354 | - */ |
|
355 | - public function get_date_modified( $context = 'view' ) { |
|
356 | - return $this->get_prop( 'date_modified', $context ); |
|
349 | + * Get date when the discount was last modified. |
|
350 | + * |
|
351 | + * @since 1.0.19 |
|
352 | + * @param string $context View or edit context. |
|
353 | + * @return string |
|
354 | + */ |
|
355 | + public function get_date_modified( $context = 'view' ) { |
|
356 | + return $this->get_prop( 'date_modified', $context ); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
360 | - * Get GMT date when the discount was last modified. |
|
361 | - * |
|
362 | - * @since 1.0.19 |
|
363 | - * @param string $context View or edit context. |
|
364 | - * @return string |
|
365 | - */ |
|
366 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
360 | + * Get GMT date when the discount was last modified. |
|
361 | + * |
|
362 | + * @since 1.0.19 |
|
363 | + * @param string $context View or edit context. |
|
364 | + * @return string |
|
365 | + */ |
|
366 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
367 | 367 | $date = $this->get_date_modified( $context ); |
368 | 368 | |
369 | 369 | if ( $date ) { |
370 | 370 | $date = get_gmt_from_date( $date ); |
371 | 371 | } |
372 | - return $date; |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Get the discount name. |
|
377 | - * |
|
378 | - * @since 1.0.19 |
|
379 | - * @param string $context View or edit context. |
|
380 | - * @return string |
|
381 | - */ |
|
382 | - public function get_name( $context = 'view' ) { |
|
383 | - return $this->get_prop( 'name', $context ); |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Alias of self::get_name(). |
|
388 | - * |
|
389 | - * @since 1.0.19 |
|
390 | - * @param string $context View or edit context. |
|
391 | - * @return string |
|
392 | - */ |
|
393 | - public function get_title( $context = 'view' ) { |
|
394 | - return $this->get_name( $context ); |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * Get the discount description. |
|
399 | - * |
|
400 | - * @since 1.0.19 |
|
401 | - * @param string $context View or edit context. |
|
402 | - * @return string |
|
403 | - */ |
|
404 | - public function get_description( $context = 'view' ) { |
|
405 | - return $this->get_prop( 'description', $context ); |
|
406 | - } |
|
407 | - |
|
408 | - /** |
|
409 | - * Alias of self::get_description(). |
|
410 | - * |
|
411 | - * @since 1.0.19 |
|
412 | - * @param string $context View or edit context. |
|
413 | - * @return string |
|
414 | - */ |
|
415 | - public function get_excerpt( $context = 'view' ) { |
|
416 | - return $this->get_description( $context ); |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Alias of self::get_description(). |
|
421 | - * |
|
422 | - * @since 1.0.19 |
|
423 | - * @param string $context View or edit context. |
|
424 | - * @return string |
|
425 | - */ |
|
426 | - public function get_summary( $context = 'view' ) { |
|
427 | - return $this->get_description( $context ); |
|
428 | - } |
|
429 | - |
|
430 | - /** |
|
431 | - * Get the owner of the discount. |
|
432 | - * |
|
433 | - * @since 1.0.19 |
|
434 | - * @param string $context View or edit context. |
|
435 | - * @return string |
|
436 | - */ |
|
437 | - public function get_author( $context = 'view' ) { |
|
438 | - return (int) $this->get_prop( 'author', $context ); |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Get the discount code. |
|
443 | - * |
|
444 | - * @since 1.0.19 |
|
445 | - * @param string $context View or edit context. |
|
446 | - * @return string |
|
447 | - */ |
|
448 | - public function get_code( $context = 'view' ) { |
|
449 | - return $this->get_prop( 'code', $context ); |
|
450 | - } |
|
451 | - |
|
452 | - /** |
|
453 | - * Alias for self::get_code(). |
|
454 | - * |
|
455 | - * @since 1.0.19 |
|
456 | - * @param string $context View or edit context. |
|
457 | - * @return string |
|
458 | - */ |
|
459 | - public function get_coupon_code( $context = 'view' ) { |
|
460 | - return $this->get_code( $context ); |
|
461 | - } |
|
462 | - |
|
463 | - /** |
|
464 | - * Alias for self::get_code(). |
|
465 | - * |
|
466 | - * @since 1.0.19 |
|
467 | - * @param string $context View or edit context. |
|
468 | - * @return string |
|
469 | - */ |
|
470 | - public function get_discount_code( $context = 'view' ) { |
|
471 | - return $this->get_code( $context ); |
|
472 | - } |
|
473 | - |
|
474 | - /** |
|
475 | - * Get the discount's amount. |
|
476 | - * |
|
477 | - * @since 1.0.19 |
|
478 | - * @param string $context View or edit context. |
|
479 | - * @return float |
|
480 | - */ |
|
481 | - public function get_amount( $context = 'view' ) { |
|
482 | - return $context == 'view' ? floatval( $this->get_prop( 'amount', $context ) ) : $this->get_prop( 'amount', $context ); |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * Get the discount's formated amount/rate. |
|
487 | - * |
|
488 | - * @since 1.0.19 |
|
489 | - * @return string |
|
490 | - */ |
|
491 | - public function get_formatted_amount() { |
|
492 | - |
|
493 | - if ( $this->is_type( 'flat' ) ) { |
|
494 | - $rate = wpinv_price( $this->get_amount() ); |
|
495 | - } else { |
|
496 | - $rate = $this->get_amount() . '%'; |
|
497 | - } |
|
498 | - |
|
499 | - return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() ); |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * Get the discount's start date. |
|
504 | - * |
|
505 | - * @since 1.0.19 |
|
506 | - * @param string $context View or edit context. |
|
507 | - * @return string |
|
508 | - */ |
|
509 | - public function get_start( $context = 'view' ) { |
|
510 | - return $this->get_prop( 'start', $context ); |
|
511 | - } |
|
512 | - |
|
513 | - /** |
|
514 | - * Alias for self::get_start(). |
|
515 | - * |
|
516 | - * @since 1.0.19 |
|
517 | - * @param string $context View or edit context. |
|
518 | - * @return string |
|
519 | - */ |
|
520 | - public function get_start_date( $context = 'view' ) { |
|
521 | - return $this->get_start( $context ); |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * Get the discount's expiration date. |
|
526 | - * |
|
527 | - * @since 1.0.19 |
|
528 | - * @param string $context View or edit context. |
|
529 | - * @return string |
|
530 | - */ |
|
531 | - public function get_expiration( $context = 'view' ) { |
|
532 | - return $this->get_prop( 'expiration', $context ); |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * Alias for self::get_expiration(). |
|
537 | - * |
|
538 | - * @since 1.0.19 |
|
539 | - * @param string $context View or edit context. |
|
540 | - * @return string |
|
541 | - */ |
|
542 | - public function get_expiration_date( $context = 'view' ) { |
|
543 | - return $this->get_expiration( $context ); |
|
544 | - } |
|
545 | - |
|
546 | - /** |
|
547 | - * Alias for self::get_expiration(). |
|
548 | - * |
|
549 | - * @since 1.0.19 |
|
550 | - * @param string $context View or edit context. |
|
551 | - * @return string |
|
552 | - */ |
|
553 | - public function get_end_date( $context = 'view' ) { |
|
554 | - return $this->get_expiration( $context ); |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * Get the discount's type. |
|
559 | - * |
|
560 | - * @since 1.0.19 |
|
561 | - * @param string $context View or edit context. |
|
562 | - * @return string |
|
563 | - */ |
|
564 | - public function get_type( $context = 'view' ) { |
|
565 | - return $this->get_prop( 'type', $context ); |
|
566 | - } |
|
567 | - |
|
568 | - /** |
|
569 | - * Get the number of times a discount has been used. |
|
570 | - * |
|
571 | - * @since 1.0.19 |
|
572 | - * @param string $context View or edit context. |
|
573 | - * @return int |
|
574 | - */ |
|
575 | - public function get_uses( $context = 'view' ) { |
|
576 | - return (int) $this->get_prop( 'uses', $context ); |
|
577 | - } |
|
578 | - |
|
579 | - /** |
|
580 | - * Get the discount's usage, i.e uses / max uses. |
|
581 | - * |
|
582 | - * @since 1.0.19 |
|
583 | - * @return string |
|
584 | - */ |
|
585 | - public function get_usage() { |
|
586 | - |
|
587 | - if ( ! $this->has_limit() ) { |
|
588 | - return $this->get_uses() . ' / ' . ' ∞'; |
|
589 | - } |
|
590 | - |
|
591 | - return $this->get_uses() . ' / ' . (int) $this->get_max_uses(); |
|
592 | - |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * Get the maximum number of time a discount can be used. |
|
597 | - * |
|
598 | - * @since 1.0.19 |
|
599 | - * @param string $context View or edit context. |
|
600 | - * @return int |
|
601 | - */ |
|
602 | - public function get_max_uses( $context = 'view' ) { |
|
603 | - $max_uses = $this->get_prop( 'max_uses', $context ); |
|
604 | - return empty( $max_uses ) ? null : $max_uses; |
|
605 | - } |
|
606 | - |
|
607 | - /** |
|
608 | - * Checks if this is a single use discount or not. |
|
609 | - * |
|
610 | - * @since 1.0.19 |
|
611 | - * @param string $context View or edit context. |
|
612 | - * @return bool |
|
613 | - */ |
|
614 | - public function get_is_single_use( $context = 'view' ) { |
|
615 | - return $this->get_prop( 'is_single_use', $context ); |
|
616 | - } |
|
617 | - |
|
618 | - /** |
|
619 | - * Get the items that can be used with this discount. |
|
620 | - * |
|
621 | - * @since 1.0.19 |
|
622 | - * @param string $context View or edit context. |
|
623 | - * @return array |
|
624 | - */ |
|
625 | - public function get_items( $context = 'view' ) { |
|
626 | - return array_filter( wp_parse_id_list( $this->get_prop( 'items', $context ) ) ); |
|
627 | - } |
|
628 | - |
|
629 | - /** |
|
630 | - * Alias for self::get_items(). |
|
631 | - * |
|
632 | - * @since 1.0.19 |
|
633 | - * @param string $context View or edit context. |
|
634 | - * @return array |
|
635 | - */ |
|
636 | - public function get_allowed_items( $context = 'view' ) { |
|
637 | - return $this->get_items( $context ); |
|
638 | - } |
|
639 | - |
|
640 | - /** |
|
641 | - * Get the items that are not allowed to use this discount. |
|
642 | - * |
|
643 | - * @since 1.0.19 |
|
644 | - * @param string $context View or edit context. |
|
645 | - * @return array |
|
646 | - */ |
|
647 | - public function get_excluded_items( $context = 'view' ) { |
|
648 | - return array_filter( wp_parse_id_list( $this->get_prop( 'excluded_items', $context ) ) ); |
|
649 | - } |
|
650 | - |
|
651 | - /** |
|
652 | - * Get the items that are required to be in the cart before using this discount. |
|
653 | - * |
|
654 | - * @since 1.0.19 |
|
655 | - * @param string $context View or edit context. |
|
656 | - * @return array |
|
657 | - */ |
|
658 | - public function get_required_items( $context = 'view' ) { |
|
659 | - return array_filter( wp_parse_id_list( $this->get_prop( 'required_items', $context ) ) ); |
|
660 | - } |
|
661 | - |
|
662 | - /** |
|
663 | - * Checks if this is a recurring discount or not. |
|
664 | - * |
|
665 | - * @since 1.0.19 |
|
666 | - * @param string $context View or edit context. |
|
667 | - * @return int|string|bool |
|
668 | - */ |
|
669 | - public function get_is_recurring( $context = 'view' ) { |
|
670 | - return $this->get_prop( 'is_recurring', $context ); |
|
671 | - } |
|
672 | - |
|
673 | - /** |
|
674 | - * Get's the minimum total amount allowed for this discount. |
|
675 | - * |
|
676 | - * @since 1.0.19 |
|
677 | - * @param string $context View or edit context. |
|
678 | - * @return float |
|
679 | - */ |
|
680 | - public function get_min_total( $context = 'view' ) { |
|
681 | - $minimum = $this->get_prop( 'min_total', $context ); |
|
682 | - return empty( $minimum ) ? null : $minimum; |
|
683 | - } |
|
684 | - |
|
685 | - /** |
|
686 | - * Alias for self::get_min_total(). |
|
687 | - * |
|
688 | - * @since 1.0.19 |
|
689 | - * @param string $context View or edit context. |
|
690 | - * @return float |
|
691 | - */ |
|
692 | - public function get_minimum_total( $context = 'view' ) { |
|
693 | - return $this->get_min_total( $context ); |
|
694 | - } |
|
695 | - |
|
696 | - /** |
|
697 | - * Get's the maximum total amount allowed for this discount. |
|
698 | - * |
|
699 | - * @since 1.0.19 |
|
700 | - * @param string $context View or edit context. |
|
701 | - * @return float |
|
702 | - */ |
|
703 | - public function get_max_total( $context = 'view' ) { |
|
704 | - $maximum = $this->get_prop( 'max_total', $context ); |
|
705 | - return empty( $maximum ) ? null : $maximum; |
|
706 | - } |
|
707 | - |
|
708 | - /** |
|
709 | - * Alias for self::get_max_total(). |
|
710 | - * |
|
711 | - * @since 1.0.19 |
|
712 | - * @param string $context View or edit context. |
|
713 | - * @return float |
|
714 | - */ |
|
715 | - public function get_maximum_total( $context = 'view' ) { |
|
716 | - return $this->get_max_total( $context ); |
|
717 | - } |
|
718 | - |
|
719 | - /** |
|
720 | - * Magic method for accessing discount properties. |
|
721 | - * |
|
722 | - * @since 1.0.15 |
|
723 | - * @access public |
|
724 | - * |
|
725 | - * @param string $key Discount data to retrieve |
|
726 | - * @param string $context View or edit context. |
|
727 | - * @return mixed Value of the given discount property (if set). |
|
728 | - */ |
|
729 | - public function get( $key, $context = 'view' ) { |
|
372 | + return $date; |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Get the discount name. |
|
377 | + * |
|
378 | + * @since 1.0.19 |
|
379 | + * @param string $context View or edit context. |
|
380 | + * @return string |
|
381 | + */ |
|
382 | + public function get_name( $context = 'view' ) { |
|
383 | + return $this->get_prop( 'name', $context ); |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Alias of self::get_name(). |
|
388 | + * |
|
389 | + * @since 1.0.19 |
|
390 | + * @param string $context View or edit context. |
|
391 | + * @return string |
|
392 | + */ |
|
393 | + public function get_title( $context = 'view' ) { |
|
394 | + return $this->get_name( $context ); |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * Get the discount description. |
|
399 | + * |
|
400 | + * @since 1.0.19 |
|
401 | + * @param string $context View or edit context. |
|
402 | + * @return string |
|
403 | + */ |
|
404 | + public function get_description( $context = 'view' ) { |
|
405 | + return $this->get_prop( 'description', $context ); |
|
406 | + } |
|
407 | + |
|
408 | + /** |
|
409 | + * Alias of self::get_description(). |
|
410 | + * |
|
411 | + * @since 1.0.19 |
|
412 | + * @param string $context View or edit context. |
|
413 | + * @return string |
|
414 | + */ |
|
415 | + public function get_excerpt( $context = 'view' ) { |
|
416 | + return $this->get_description( $context ); |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Alias of self::get_description(). |
|
421 | + * |
|
422 | + * @since 1.0.19 |
|
423 | + * @param string $context View or edit context. |
|
424 | + * @return string |
|
425 | + */ |
|
426 | + public function get_summary( $context = 'view' ) { |
|
427 | + return $this->get_description( $context ); |
|
428 | + } |
|
429 | + |
|
430 | + /** |
|
431 | + * Get the owner of the discount. |
|
432 | + * |
|
433 | + * @since 1.0.19 |
|
434 | + * @param string $context View or edit context. |
|
435 | + * @return string |
|
436 | + */ |
|
437 | + public function get_author( $context = 'view' ) { |
|
438 | + return (int) $this->get_prop( 'author', $context ); |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Get the discount code. |
|
443 | + * |
|
444 | + * @since 1.0.19 |
|
445 | + * @param string $context View or edit context. |
|
446 | + * @return string |
|
447 | + */ |
|
448 | + public function get_code( $context = 'view' ) { |
|
449 | + return $this->get_prop( 'code', $context ); |
|
450 | + } |
|
451 | + |
|
452 | + /** |
|
453 | + * Alias for self::get_code(). |
|
454 | + * |
|
455 | + * @since 1.0.19 |
|
456 | + * @param string $context View or edit context. |
|
457 | + * @return string |
|
458 | + */ |
|
459 | + public function get_coupon_code( $context = 'view' ) { |
|
460 | + return $this->get_code( $context ); |
|
461 | + } |
|
462 | + |
|
463 | + /** |
|
464 | + * Alias for self::get_code(). |
|
465 | + * |
|
466 | + * @since 1.0.19 |
|
467 | + * @param string $context View or edit context. |
|
468 | + * @return string |
|
469 | + */ |
|
470 | + public function get_discount_code( $context = 'view' ) { |
|
471 | + return $this->get_code( $context ); |
|
472 | + } |
|
473 | + |
|
474 | + /** |
|
475 | + * Get the discount's amount. |
|
476 | + * |
|
477 | + * @since 1.0.19 |
|
478 | + * @param string $context View or edit context. |
|
479 | + * @return float |
|
480 | + */ |
|
481 | + public function get_amount( $context = 'view' ) { |
|
482 | + return $context == 'view' ? floatval( $this->get_prop( 'amount', $context ) ) : $this->get_prop( 'amount', $context ); |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * Get the discount's formated amount/rate. |
|
487 | + * |
|
488 | + * @since 1.0.19 |
|
489 | + * @return string |
|
490 | + */ |
|
491 | + public function get_formatted_amount() { |
|
492 | + |
|
493 | + if ( $this->is_type( 'flat' ) ) { |
|
494 | + $rate = wpinv_price( $this->get_amount() ); |
|
495 | + } else { |
|
496 | + $rate = $this->get_amount() . '%'; |
|
497 | + } |
|
498 | + |
|
499 | + return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() ); |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * Get the discount's start date. |
|
504 | + * |
|
505 | + * @since 1.0.19 |
|
506 | + * @param string $context View or edit context. |
|
507 | + * @return string |
|
508 | + */ |
|
509 | + public function get_start( $context = 'view' ) { |
|
510 | + return $this->get_prop( 'start', $context ); |
|
511 | + } |
|
512 | + |
|
513 | + /** |
|
514 | + * Alias for self::get_start(). |
|
515 | + * |
|
516 | + * @since 1.0.19 |
|
517 | + * @param string $context View or edit context. |
|
518 | + * @return string |
|
519 | + */ |
|
520 | + public function get_start_date( $context = 'view' ) { |
|
521 | + return $this->get_start( $context ); |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * Get the discount's expiration date. |
|
526 | + * |
|
527 | + * @since 1.0.19 |
|
528 | + * @param string $context View or edit context. |
|
529 | + * @return string |
|
530 | + */ |
|
531 | + public function get_expiration( $context = 'view' ) { |
|
532 | + return $this->get_prop( 'expiration', $context ); |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * Alias for self::get_expiration(). |
|
537 | + * |
|
538 | + * @since 1.0.19 |
|
539 | + * @param string $context View or edit context. |
|
540 | + * @return string |
|
541 | + */ |
|
542 | + public function get_expiration_date( $context = 'view' ) { |
|
543 | + return $this->get_expiration( $context ); |
|
544 | + } |
|
545 | + |
|
546 | + /** |
|
547 | + * Alias for self::get_expiration(). |
|
548 | + * |
|
549 | + * @since 1.0.19 |
|
550 | + * @param string $context View or edit context. |
|
551 | + * @return string |
|
552 | + */ |
|
553 | + public function get_end_date( $context = 'view' ) { |
|
554 | + return $this->get_expiration( $context ); |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * Get the discount's type. |
|
559 | + * |
|
560 | + * @since 1.0.19 |
|
561 | + * @param string $context View or edit context. |
|
562 | + * @return string |
|
563 | + */ |
|
564 | + public function get_type( $context = 'view' ) { |
|
565 | + return $this->get_prop( 'type', $context ); |
|
566 | + } |
|
567 | + |
|
568 | + /** |
|
569 | + * Get the number of times a discount has been used. |
|
570 | + * |
|
571 | + * @since 1.0.19 |
|
572 | + * @param string $context View or edit context. |
|
573 | + * @return int |
|
574 | + */ |
|
575 | + public function get_uses( $context = 'view' ) { |
|
576 | + return (int) $this->get_prop( 'uses', $context ); |
|
577 | + } |
|
578 | + |
|
579 | + /** |
|
580 | + * Get the discount's usage, i.e uses / max uses. |
|
581 | + * |
|
582 | + * @since 1.0.19 |
|
583 | + * @return string |
|
584 | + */ |
|
585 | + public function get_usage() { |
|
586 | + |
|
587 | + if ( ! $this->has_limit() ) { |
|
588 | + return $this->get_uses() . ' / ' . ' ∞'; |
|
589 | + } |
|
590 | + |
|
591 | + return $this->get_uses() . ' / ' . (int) $this->get_max_uses(); |
|
592 | + |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * Get the maximum number of time a discount can be used. |
|
597 | + * |
|
598 | + * @since 1.0.19 |
|
599 | + * @param string $context View or edit context. |
|
600 | + * @return int |
|
601 | + */ |
|
602 | + public function get_max_uses( $context = 'view' ) { |
|
603 | + $max_uses = $this->get_prop( 'max_uses', $context ); |
|
604 | + return empty( $max_uses ) ? null : $max_uses; |
|
605 | + } |
|
606 | + |
|
607 | + /** |
|
608 | + * Checks if this is a single use discount or not. |
|
609 | + * |
|
610 | + * @since 1.0.19 |
|
611 | + * @param string $context View or edit context. |
|
612 | + * @return bool |
|
613 | + */ |
|
614 | + public function get_is_single_use( $context = 'view' ) { |
|
615 | + return $this->get_prop( 'is_single_use', $context ); |
|
616 | + } |
|
617 | + |
|
618 | + /** |
|
619 | + * Get the items that can be used with this discount. |
|
620 | + * |
|
621 | + * @since 1.0.19 |
|
622 | + * @param string $context View or edit context. |
|
623 | + * @return array |
|
624 | + */ |
|
625 | + public function get_items( $context = 'view' ) { |
|
626 | + return array_filter( wp_parse_id_list( $this->get_prop( 'items', $context ) ) ); |
|
627 | + } |
|
628 | + |
|
629 | + /** |
|
630 | + * Alias for self::get_items(). |
|
631 | + * |
|
632 | + * @since 1.0.19 |
|
633 | + * @param string $context View or edit context. |
|
634 | + * @return array |
|
635 | + */ |
|
636 | + public function get_allowed_items( $context = 'view' ) { |
|
637 | + return $this->get_items( $context ); |
|
638 | + } |
|
639 | + |
|
640 | + /** |
|
641 | + * Get the items that are not allowed to use this discount. |
|
642 | + * |
|
643 | + * @since 1.0.19 |
|
644 | + * @param string $context View or edit context. |
|
645 | + * @return array |
|
646 | + */ |
|
647 | + public function get_excluded_items( $context = 'view' ) { |
|
648 | + return array_filter( wp_parse_id_list( $this->get_prop( 'excluded_items', $context ) ) ); |
|
649 | + } |
|
650 | + |
|
651 | + /** |
|
652 | + * Get the items that are required to be in the cart before using this discount. |
|
653 | + * |
|
654 | + * @since 1.0.19 |
|
655 | + * @param string $context View or edit context. |
|
656 | + * @return array |
|
657 | + */ |
|
658 | + public function get_required_items( $context = 'view' ) { |
|
659 | + return array_filter( wp_parse_id_list( $this->get_prop( 'required_items', $context ) ) ); |
|
660 | + } |
|
661 | + |
|
662 | + /** |
|
663 | + * Checks if this is a recurring discount or not. |
|
664 | + * |
|
665 | + * @since 1.0.19 |
|
666 | + * @param string $context View or edit context. |
|
667 | + * @return int|string|bool |
|
668 | + */ |
|
669 | + public function get_is_recurring( $context = 'view' ) { |
|
670 | + return $this->get_prop( 'is_recurring', $context ); |
|
671 | + } |
|
672 | + |
|
673 | + /** |
|
674 | + * Get's the minimum total amount allowed for this discount. |
|
675 | + * |
|
676 | + * @since 1.0.19 |
|
677 | + * @param string $context View or edit context. |
|
678 | + * @return float |
|
679 | + */ |
|
680 | + public function get_min_total( $context = 'view' ) { |
|
681 | + $minimum = $this->get_prop( 'min_total', $context ); |
|
682 | + return empty( $minimum ) ? null : $minimum; |
|
683 | + } |
|
684 | + |
|
685 | + /** |
|
686 | + * Alias for self::get_min_total(). |
|
687 | + * |
|
688 | + * @since 1.0.19 |
|
689 | + * @param string $context View or edit context. |
|
690 | + * @return float |
|
691 | + */ |
|
692 | + public function get_minimum_total( $context = 'view' ) { |
|
693 | + return $this->get_min_total( $context ); |
|
694 | + } |
|
695 | + |
|
696 | + /** |
|
697 | + * Get's the maximum total amount allowed for this discount. |
|
698 | + * |
|
699 | + * @since 1.0.19 |
|
700 | + * @param string $context View or edit context. |
|
701 | + * @return float |
|
702 | + */ |
|
703 | + public function get_max_total( $context = 'view' ) { |
|
704 | + $maximum = $this->get_prop( 'max_total', $context ); |
|
705 | + return empty( $maximum ) ? null : $maximum; |
|
706 | + } |
|
707 | + |
|
708 | + /** |
|
709 | + * Alias for self::get_max_total(). |
|
710 | + * |
|
711 | + * @since 1.0.19 |
|
712 | + * @param string $context View or edit context. |
|
713 | + * @return float |
|
714 | + */ |
|
715 | + public function get_maximum_total( $context = 'view' ) { |
|
716 | + return $this->get_max_total( $context ); |
|
717 | + } |
|
718 | + |
|
719 | + /** |
|
720 | + * Magic method for accessing discount properties. |
|
721 | + * |
|
722 | + * @since 1.0.15 |
|
723 | + * @access public |
|
724 | + * |
|
725 | + * @param string $key Discount data to retrieve |
|
726 | + * @param string $context View or edit context. |
|
727 | + * @return mixed Value of the given discount property (if set). |
|
728 | + */ |
|
729 | + public function get( $key, $context = 'view' ) { |
|
730 | 730 | return $this->get_prop( $key, $context ); |
731 | - } |
|
731 | + } |
|
732 | 732 | |
733 | - /* |
|
733 | + /* |
|
734 | 734 | |-------------------------------------------------------------------------- |
735 | 735 | | Setters |
736 | 736 | |-------------------------------------------------------------------------- |
@@ -740,41 +740,41 @@ discard block |
||
740 | 740 | | object. |
741 | 741 | */ |
742 | 742 | |
743 | - /** |
|
744 | - * Sets discount status. |
|
745 | - * |
|
746 | - * @since 1.0.19 |
|
747 | - * @param string $status New status. |
|
748 | - * @return array details of change. |
|
749 | - */ |
|
750 | - public function set_status( $status ) { |
|
743 | + /** |
|
744 | + * Sets discount status. |
|
745 | + * |
|
746 | + * @since 1.0.19 |
|
747 | + * @param string $status New status. |
|
748 | + * @return array details of change. |
|
749 | + */ |
|
750 | + public function set_status( $status ) { |
|
751 | 751 | $old_status = $this->get_status(); |
752 | 752 | |
753 | 753 | $this->set_prop( 'status', $status ); |
754 | 754 | |
755 | - return array( |
|
756 | - 'from' => $old_status, |
|
757 | - 'to' => $status, |
|
758 | - ); |
|
755 | + return array( |
|
756 | + 'from' => $old_status, |
|
757 | + 'to' => $status, |
|
758 | + ); |
|
759 | 759 | } |
760 | 760 | |
761 | 761 | /** |
762 | - * Set plugin version when the discount was created. |
|
763 | - * |
|
764 | - * @since 1.0.19 |
|
765 | - */ |
|
766 | - public function set_version( $value ) { |
|
767 | - $this->set_prop( 'version', $value ); |
|
762 | + * Set plugin version when the discount was created. |
|
763 | + * |
|
764 | + * @since 1.0.19 |
|
765 | + */ |
|
766 | + public function set_version( $value ) { |
|
767 | + $this->set_prop( 'version', $value ); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | /** |
771 | - * Set date when the discount was created. |
|
772 | - * |
|
773 | - * @since 1.0.19 |
|
774 | - * @param string $value Value to set. |
|
771 | + * Set date when the discount was created. |
|
772 | + * |
|
773 | + * @since 1.0.19 |
|
774 | + * @param string $value Value to set. |
|
775 | 775 | * @return bool Whether or not the date was set. |
776 | - */ |
|
777 | - public function set_date_created( $value ) { |
|
776 | + */ |
|
777 | + public function set_date_created( $value ) { |
|
778 | 778 | $date = strtotime( $value ); |
779 | 779 | |
780 | 780 | if ( $date ) { |
@@ -787,13 +787,13 @@ discard block |
||
787 | 787 | } |
788 | 788 | |
789 | 789 | /** |
790 | - * Set date when the discount was last modified. |
|
791 | - * |
|
792 | - * @since 1.0.19 |
|
793 | - * @param string $value Value to set. |
|
790 | + * Set date when the discount was last modified. |
|
791 | + * |
|
792 | + * @since 1.0.19 |
|
793 | + * @param string $value Value to set. |
|
794 | 794 | * @return bool Whether or not the date was set. |
795 | - */ |
|
796 | - public function set_date_modified( $value ) { |
|
795 | + */ |
|
796 | + public function set_date_modified( $value ) { |
|
797 | 797 | $date = strtotime( $value ); |
798 | 798 | |
799 | 799 | if ( $date ) { |
@@ -806,334 +806,334 @@ discard block |
||
806 | 806 | } |
807 | 807 | |
808 | 808 | /** |
809 | - * Set the discount name. |
|
810 | - * |
|
811 | - * @since 1.0.19 |
|
812 | - * @param string $value New name. |
|
813 | - */ |
|
814 | - public function set_name( $value ) { |
|
809 | + * Set the discount name. |
|
810 | + * |
|
811 | + * @since 1.0.19 |
|
812 | + * @param string $value New name. |
|
813 | + */ |
|
814 | + public function set_name( $value ) { |
|
815 | 815 | $name = sanitize_text_field( $value ); |
816 | - $this->set_prop( 'name', $name ); |
|
816 | + $this->set_prop( 'name', $name ); |
|
817 | 817 | } |
818 | 818 | |
819 | 819 | /** |
820 | - * Alias of self::set_name(). |
|
821 | - * |
|
822 | - * @since 1.0.19 |
|
823 | - * @param string $value New name. |
|
824 | - */ |
|
825 | - public function set_title( $value ) { |
|
826 | - $this->set_name( $value ); |
|
820 | + * Alias of self::set_name(). |
|
821 | + * |
|
822 | + * @since 1.0.19 |
|
823 | + * @param string $value New name. |
|
824 | + */ |
|
825 | + public function set_title( $value ) { |
|
826 | + $this->set_name( $value ); |
|
827 | 827 | } |
828 | 828 | |
829 | 829 | /** |
830 | - * Set the discount description. |
|
831 | - * |
|
832 | - * @since 1.0.19 |
|
833 | - * @param string $value New description. |
|
834 | - */ |
|
835 | - public function set_description( $value ) { |
|
830 | + * Set the discount description. |
|
831 | + * |
|
832 | + * @since 1.0.19 |
|
833 | + * @param string $value New description. |
|
834 | + */ |
|
835 | + public function set_description( $value ) { |
|
836 | 836 | $description = wp_kses_post( $value ); |
837 | - return $this->set_prop( 'description', $description ); |
|
838 | - } |
|
839 | - |
|
840 | - /** |
|
841 | - * Alias of self::set_description(). |
|
842 | - * |
|
843 | - * @since 1.0.19 |
|
844 | - * @param string $value New description. |
|
845 | - */ |
|
846 | - public function set_excerpt( $value ) { |
|
847 | - $this->set_description( $value ); |
|
848 | - } |
|
849 | - |
|
850 | - /** |
|
851 | - * Alias of self::set_description(). |
|
852 | - * |
|
853 | - * @since 1.0.19 |
|
854 | - * @param string $value New description. |
|
855 | - */ |
|
856 | - public function set_summary( $value ) { |
|
857 | - $this->set_description( $value ); |
|
858 | - } |
|
859 | - |
|
860 | - /** |
|
861 | - * Set the owner of the discount. |
|
862 | - * |
|
863 | - * @since 1.0.19 |
|
864 | - * @param int $value New author. |
|
865 | - */ |
|
866 | - public function set_author( $value ) { |
|
867 | - $this->set_prop( 'author', (int) $value ); |
|
868 | - } |
|
869 | - |
|
870 | - /** |
|
871 | - * Sets the discount code. |
|
872 | - * |
|
873 | - * @since 1.0.19 |
|
874 | - * @param string $value New discount code. |
|
875 | - */ |
|
876 | - public function set_code( $value ) { |
|
877 | - $code = sanitize_text_field( $value ); |
|
878 | - $this->set_prop( 'code', $code ); |
|
879 | - } |
|
880 | - |
|
881 | - /** |
|
882 | - * Alias of self::set_code(). |
|
883 | - * |
|
884 | - * @since 1.0.19 |
|
885 | - * @param string $value New discount code. |
|
886 | - */ |
|
887 | - public function set_coupon_code( $value ) { |
|
888 | - $this->set_code( $value ); |
|
889 | - } |
|
890 | - |
|
891 | - /** |
|
892 | - * Alias of self::set_code(). |
|
893 | - * |
|
894 | - * @since 1.0.19 |
|
895 | - * @param string $value New discount code. |
|
896 | - */ |
|
897 | - public function set_discount_code( $value ) { |
|
898 | - $this->set_code( $value ); |
|
899 | - } |
|
900 | - |
|
901 | - /** |
|
902 | - * Sets the discount amount. |
|
903 | - * |
|
904 | - * @since 1.0.19 |
|
905 | - * @param float $value New discount code. |
|
906 | - */ |
|
907 | - public function set_amount( $value ) { |
|
908 | - $amount = floatval( wpinv_sanitize_amount( $value ) ); |
|
909 | - $this->set_prop( 'amount', $amount ); |
|
910 | - } |
|
911 | - |
|
912 | - /** |
|
913 | - * Sets the discount's start date. |
|
914 | - * |
|
915 | - * @since 1.0.19 |
|
916 | - * @param float $value New start date. |
|
917 | - */ |
|
918 | - public function set_start( $value ) { |
|
919 | - $date = strtotime( $value ); |
|
837 | + return $this->set_prop( 'description', $description ); |
|
838 | + } |
|
839 | + |
|
840 | + /** |
|
841 | + * Alias of self::set_description(). |
|
842 | + * |
|
843 | + * @since 1.0.19 |
|
844 | + * @param string $value New description. |
|
845 | + */ |
|
846 | + public function set_excerpt( $value ) { |
|
847 | + $this->set_description( $value ); |
|
848 | + } |
|
849 | + |
|
850 | + /** |
|
851 | + * Alias of self::set_description(). |
|
852 | + * |
|
853 | + * @since 1.0.19 |
|
854 | + * @param string $value New description. |
|
855 | + */ |
|
856 | + public function set_summary( $value ) { |
|
857 | + $this->set_description( $value ); |
|
858 | + } |
|
859 | + |
|
860 | + /** |
|
861 | + * Set the owner of the discount. |
|
862 | + * |
|
863 | + * @since 1.0.19 |
|
864 | + * @param int $value New author. |
|
865 | + */ |
|
866 | + public function set_author( $value ) { |
|
867 | + $this->set_prop( 'author', (int) $value ); |
|
868 | + } |
|
869 | + |
|
870 | + /** |
|
871 | + * Sets the discount code. |
|
872 | + * |
|
873 | + * @since 1.0.19 |
|
874 | + * @param string $value New discount code. |
|
875 | + */ |
|
876 | + public function set_code( $value ) { |
|
877 | + $code = sanitize_text_field( $value ); |
|
878 | + $this->set_prop( 'code', $code ); |
|
879 | + } |
|
880 | + |
|
881 | + /** |
|
882 | + * Alias of self::set_code(). |
|
883 | + * |
|
884 | + * @since 1.0.19 |
|
885 | + * @param string $value New discount code. |
|
886 | + */ |
|
887 | + public function set_coupon_code( $value ) { |
|
888 | + $this->set_code( $value ); |
|
889 | + } |
|
890 | + |
|
891 | + /** |
|
892 | + * Alias of self::set_code(). |
|
893 | + * |
|
894 | + * @since 1.0.19 |
|
895 | + * @param string $value New discount code. |
|
896 | + */ |
|
897 | + public function set_discount_code( $value ) { |
|
898 | + $this->set_code( $value ); |
|
899 | + } |
|
900 | + |
|
901 | + /** |
|
902 | + * Sets the discount amount. |
|
903 | + * |
|
904 | + * @since 1.0.19 |
|
905 | + * @param float $value New discount code. |
|
906 | + */ |
|
907 | + public function set_amount( $value ) { |
|
908 | + $amount = floatval( wpinv_sanitize_amount( $value ) ); |
|
909 | + $this->set_prop( 'amount', $amount ); |
|
910 | + } |
|
911 | + |
|
912 | + /** |
|
913 | + * Sets the discount's start date. |
|
914 | + * |
|
915 | + * @since 1.0.19 |
|
916 | + * @param float $value New start date. |
|
917 | + */ |
|
918 | + public function set_start( $value ) { |
|
919 | + $date = strtotime( $value ); |
|
920 | 920 | |
921 | 921 | if ( $date ) { |
922 | 922 | $this->set_prop( 'start', date( 'Y-m-d H:i', $date ) ); |
923 | 923 | return true; |
924 | - } |
|
924 | + } |
|
925 | 925 | |
926 | - $this->set_prop( 'start', '' ); |
|
926 | + $this->set_prop( 'start', '' ); |
|
927 | 927 | |
928 | 928 | return false; |
929 | - } |
|
930 | - |
|
931 | - /** |
|
932 | - * Alias of self::set_start(). |
|
933 | - * |
|
934 | - * @since 1.0.19 |
|
935 | - * @param string $value New start date. |
|
936 | - */ |
|
937 | - public function set_start_date( $value ) { |
|
938 | - $this->set_start( $value ); |
|
939 | - } |
|
940 | - |
|
941 | - /** |
|
942 | - * Sets the discount's expiration date. |
|
943 | - * |
|
944 | - * @since 1.0.19 |
|
945 | - * @param float $value New expiration date. |
|
946 | - */ |
|
947 | - public function set_expiration( $value ) { |
|
948 | - $date = strtotime( $value ); |
|
929 | + } |
|
930 | + |
|
931 | + /** |
|
932 | + * Alias of self::set_start(). |
|
933 | + * |
|
934 | + * @since 1.0.19 |
|
935 | + * @param string $value New start date. |
|
936 | + */ |
|
937 | + public function set_start_date( $value ) { |
|
938 | + $this->set_start( $value ); |
|
939 | + } |
|
940 | + |
|
941 | + /** |
|
942 | + * Sets the discount's expiration date. |
|
943 | + * |
|
944 | + * @since 1.0.19 |
|
945 | + * @param float $value New expiration date. |
|
946 | + */ |
|
947 | + public function set_expiration( $value ) { |
|
948 | + $date = strtotime( $value ); |
|
949 | 949 | |
950 | 950 | if ( $date ) { |
951 | 951 | $this->set_prop( 'expiration', date( 'Y-m-d H:i', $date ) ); |
952 | 952 | return true; |
953 | 953 | } |
954 | 954 | |
955 | - $this->set_prop( 'expiration', '' ); |
|
955 | + $this->set_prop( 'expiration', '' ); |
|
956 | 956 | return false; |
957 | - } |
|
958 | - |
|
959 | - /** |
|
960 | - * Alias of self::set_expiration(). |
|
961 | - * |
|
962 | - * @since 1.0.19 |
|
963 | - * @param string $value New expiration date. |
|
964 | - */ |
|
965 | - public function set_expiration_date( $value ) { |
|
966 | - $this->set_expiration( $value ); |
|
967 | - } |
|
968 | - |
|
969 | - /** |
|
970 | - * Alias of self::set_expiration(). |
|
971 | - * |
|
972 | - * @since 1.0.19 |
|
973 | - * @param string $value New expiration date. |
|
974 | - */ |
|
975 | - public function set_end_date( $value ) { |
|
976 | - $this->set_expiration( $value ); |
|
977 | - } |
|
978 | - |
|
979 | - /** |
|
980 | - * Sets the discount type. |
|
981 | - * |
|
982 | - * @since 1.0.19 |
|
983 | - * @param string $value New discount type. |
|
984 | - */ |
|
985 | - public function set_type( $value ) { |
|
986 | - if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) { |
|
987 | - $this->set_prop( 'type', sanitize_text_field( $value ) ); |
|
988 | - } |
|
989 | - } |
|
990 | - |
|
991 | - /** |
|
992 | - * Sets the number of times a discount has been used. |
|
993 | - * |
|
994 | - * @since 1.0.19 |
|
995 | - * @param int $value usage count. |
|
996 | - */ |
|
997 | - public function set_uses( $value ) { |
|
998 | - |
|
999 | - $value = (int) $value; |
|
1000 | - |
|
1001 | - if ( $value < 0 ) { |
|
1002 | - $value = 0; |
|
1003 | - } |
|
1004 | - |
|
1005 | - $this->set_prop( 'uses', (int) $value ); |
|
1006 | - } |
|
1007 | - |
|
1008 | - /** |
|
1009 | - * Sets the maximum number of times a discount can be used. |
|
1010 | - * |
|
1011 | - * @since 1.0.19 |
|
1012 | - * @param int $value maximum usage count. |
|
1013 | - */ |
|
1014 | - public function set_max_uses( $value ) { |
|
1015 | - $this->set_prop( 'max_uses', absint( $value ) ); |
|
1016 | - } |
|
1017 | - |
|
1018 | - /** |
|
1019 | - * Sets if this is a single use discount or not. |
|
1020 | - * |
|
1021 | - * @since 1.0.19 |
|
1022 | - * @param int|bool $value is single use. |
|
1023 | - */ |
|
1024 | - public function set_is_single_use( $value ) { |
|
1025 | - $this->set_prop( 'is_single_use', (bool) $value ); |
|
1026 | - } |
|
1027 | - |
|
1028 | - /** |
|
1029 | - * Sets the items that can be used with this discount. |
|
1030 | - * |
|
1031 | - * @since 1.0.19 |
|
1032 | - * @param array $value items. |
|
1033 | - */ |
|
1034 | - public function set_items( $value ) { |
|
1035 | - $this->set_prop( 'items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1036 | - } |
|
1037 | - |
|
1038 | - /** |
|
1039 | - * Alias for self::set_items(). |
|
1040 | - * |
|
1041 | - * @since 1.0.19 |
|
1042 | - * @param array $value items. |
|
1043 | - */ |
|
1044 | - public function set_allowed_items( $value ) { |
|
1045 | - $this->set_items( $value ); |
|
1046 | - } |
|
1047 | - |
|
1048 | - /** |
|
1049 | - * Sets the items that can not be used with this discount. |
|
1050 | - * |
|
1051 | - * @since 1.0.19 |
|
1052 | - * @param array $value items. |
|
1053 | - */ |
|
1054 | - public function set_excluded_items( $value ) { |
|
1055 | - $this->set_prop( 'excluded_items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1056 | - } |
|
1057 | - |
|
1058 | - /** |
|
1059 | - * Sets the items that are required to be in the cart before using this discount. |
|
1060 | - * |
|
1061 | - * @since 1.0.19 |
|
1062 | - * @param array $value items. |
|
1063 | - */ |
|
1064 | - public function set_required_items( $value ) { |
|
1065 | - $this->set_prop( 'required_items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1066 | - } |
|
1067 | - |
|
1068 | - /** |
|
1069 | - * Sets if this is a recurring discounts or not. |
|
1070 | - * |
|
1071 | - * @since 1.0.19 |
|
1072 | - * @param int|bool $value is recurring. |
|
1073 | - */ |
|
1074 | - public function set_is_recurring( $value ) { |
|
1075 | - $this->set_prop( 'is_recurring', (bool) $value ); |
|
1076 | - } |
|
1077 | - |
|
1078 | - /** |
|
1079 | - * Sets the minimum total that can not be used with this discount. |
|
1080 | - * |
|
1081 | - * @since 1.0.19 |
|
1082 | - * @param float $value minimum total. |
|
1083 | - */ |
|
1084 | - public function set_min_total( $value ) { |
|
1085 | - $this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1086 | - } |
|
1087 | - |
|
1088 | - /** |
|
1089 | - * Alias for self::set_min_total(). |
|
1090 | - * |
|
1091 | - * @since 1.0.19 |
|
1092 | - * @param float $value minimum total. |
|
1093 | - */ |
|
1094 | - public function set_minimum_total( $value ) { |
|
1095 | - $this->set_min_total( $value ); |
|
1096 | - } |
|
1097 | - |
|
1098 | - /** |
|
1099 | - * Sets the maximum total that can not be used with this discount. |
|
1100 | - * |
|
1101 | - * @since 1.0.19 |
|
1102 | - * @param float $value maximum total. |
|
1103 | - */ |
|
1104 | - public function set_max_total( $value ) { |
|
1105 | - $this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1106 | - } |
|
1107 | - |
|
1108 | - /** |
|
1109 | - * Alias for self::set_max_total(). |
|
1110 | - * |
|
1111 | - * @since 1.0.19 |
|
1112 | - * @param float $value maximum total. |
|
1113 | - */ |
|
1114 | - public function set_maximum_total( $value ) { |
|
1115 | - $this->set_max_total( $value ); |
|
1116 | - } |
|
1117 | - |
|
1118 | - /** |
|
1119 | - * @deprecated |
|
1120 | - */ |
|
1121 | - public function refresh(){} |
|
1122 | - |
|
1123 | - /** |
|
1124 | - * @deprecated |
|
1125 | - * |
|
1126 | - */ |
|
1127 | - public function update_status( $status = 'publish' ){ |
|
1128 | - |
|
1129 | - if ( $this->exists() && $this->get_status() != $status ) { |
|
1130 | - $this->set_status( $status ); |
|
1131 | - $this->save(); |
|
1132 | - } |
|
1133 | - |
|
1134 | - } |
|
1135 | - |
|
1136 | - /* |
|
957 | + } |
|
958 | + |
|
959 | + /** |
|
960 | + * Alias of self::set_expiration(). |
|
961 | + * |
|
962 | + * @since 1.0.19 |
|
963 | + * @param string $value New expiration date. |
|
964 | + */ |
|
965 | + public function set_expiration_date( $value ) { |
|
966 | + $this->set_expiration( $value ); |
|
967 | + } |
|
968 | + |
|
969 | + /** |
|
970 | + * Alias of self::set_expiration(). |
|
971 | + * |
|
972 | + * @since 1.0.19 |
|
973 | + * @param string $value New expiration date. |
|
974 | + */ |
|
975 | + public function set_end_date( $value ) { |
|
976 | + $this->set_expiration( $value ); |
|
977 | + } |
|
978 | + |
|
979 | + /** |
|
980 | + * Sets the discount type. |
|
981 | + * |
|
982 | + * @since 1.0.19 |
|
983 | + * @param string $value New discount type. |
|
984 | + */ |
|
985 | + public function set_type( $value ) { |
|
986 | + if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) { |
|
987 | + $this->set_prop( 'type', sanitize_text_field( $value ) ); |
|
988 | + } |
|
989 | + } |
|
990 | + |
|
991 | + /** |
|
992 | + * Sets the number of times a discount has been used. |
|
993 | + * |
|
994 | + * @since 1.0.19 |
|
995 | + * @param int $value usage count. |
|
996 | + */ |
|
997 | + public function set_uses( $value ) { |
|
998 | + |
|
999 | + $value = (int) $value; |
|
1000 | + |
|
1001 | + if ( $value < 0 ) { |
|
1002 | + $value = 0; |
|
1003 | + } |
|
1004 | + |
|
1005 | + $this->set_prop( 'uses', (int) $value ); |
|
1006 | + } |
|
1007 | + |
|
1008 | + /** |
|
1009 | + * Sets the maximum number of times a discount can be used. |
|
1010 | + * |
|
1011 | + * @since 1.0.19 |
|
1012 | + * @param int $value maximum usage count. |
|
1013 | + */ |
|
1014 | + public function set_max_uses( $value ) { |
|
1015 | + $this->set_prop( 'max_uses', absint( $value ) ); |
|
1016 | + } |
|
1017 | + |
|
1018 | + /** |
|
1019 | + * Sets if this is a single use discount or not. |
|
1020 | + * |
|
1021 | + * @since 1.0.19 |
|
1022 | + * @param int|bool $value is single use. |
|
1023 | + */ |
|
1024 | + public function set_is_single_use( $value ) { |
|
1025 | + $this->set_prop( 'is_single_use', (bool) $value ); |
|
1026 | + } |
|
1027 | + |
|
1028 | + /** |
|
1029 | + * Sets the items that can be used with this discount. |
|
1030 | + * |
|
1031 | + * @since 1.0.19 |
|
1032 | + * @param array $value items. |
|
1033 | + */ |
|
1034 | + public function set_items( $value ) { |
|
1035 | + $this->set_prop( 'items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1036 | + } |
|
1037 | + |
|
1038 | + /** |
|
1039 | + * Alias for self::set_items(). |
|
1040 | + * |
|
1041 | + * @since 1.0.19 |
|
1042 | + * @param array $value items. |
|
1043 | + */ |
|
1044 | + public function set_allowed_items( $value ) { |
|
1045 | + $this->set_items( $value ); |
|
1046 | + } |
|
1047 | + |
|
1048 | + /** |
|
1049 | + * Sets the items that can not be used with this discount. |
|
1050 | + * |
|
1051 | + * @since 1.0.19 |
|
1052 | + * @param array $value items. |
|
1053 | + */ |
|
1054 | + public function set_excluded_items( $value ) { |
|
1055 | + $this->set_prop( 'excluded_items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1056 | + } |
|
1057 | + |
|
1058 | + /** |
|
1059 | + * Sets the items that are required to be in the cart before using this discount. |
|
1060 | + * |
|
1061 | + * @since 1.0.19 |
|
1062 | + * @param array $value items. |
|
1063 | + */ |
|
1064 | + public function set_required_items( $value ) { |
|
1065 | + $this->set_prop( 'required_items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1066 | + } |
|
1067 | + |
|
1068 | + /** |
|
1069 | + * Sets if this is a recurring discounts or not. |
|
1070 | + * |
|
1071 | + * @since 1.0.19 |
|
1072 | + * @param int|bool $value is recurring. |
|
1073 | + */ |
|
1074 | + public function set_is_recurring( $value ) { |
|
1075 | + $this->set_prop( 'is_recurring', (bool) $value ); |
|
1076 | + } |
|
1077 | + |
|
1078 | + /** |
|
1079 | + * Sets the minimum total that can not be used with this discount. |
|
1080 | + * |
|
1081 | + * @since 1.0.19 |
|
1082 | + * @param float $value minimum total. |
|
1083 | + */ |
|
1084 | + public function set_min_total( $value ) { |
|
1085 | + $this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1086 | + } |
|
1087 | + |
|
1088 | + /** |
|
1089 | + * Alias for self::set_min_total(). |
|
1090 | + * |
|
1091 | + * @since 1.0.19 |
|
1092 | + * @param float $value minimum total. |
|
1093 | + */ |
|
1094 | + public function set_minimum_total( $value ) { |
|
1095 | + $this->set_min_total( $value ); |
|
1096 | + } |
|
1097 | + |
|
1098 | + /** |
|
1099 | + * Sets the maximum total that can not be used with this discount. |
|
1100 | + * |
|
1101 | + * @since 1.0.19 |
|
1102 | + * @param float $value maximum total. |
|
1103 | + */ |
|
1104 | + public function set_max_total( $value ) { |
|
1105 | + $this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1106 | + } |
|
1107 | + |
|
1108 | + /** |
|
1109 | + * Alias for self::set_max_total(). |
|
1110 | + * |
|
1111 | + * @since 1.0.19 |
|
1112 | + * @param float $value maximum total. |
|
1113 | + */ |
|
1114 | + public function set_maximum_total( $value ) { |
|
1115 | + $this->set_max_total( $value ); |
|
1116 | + } |
|
1117 | + |
|
1118 | + /** |
|
1119 | + * @deprecated |
|
1120 | + */ |
|
1121 | + public function refresh(){} |
|
1122 | + |
|
1123 | + /** |
|
1124 | + * @deprecated |
|
1125 | + * |
|
1126 | + */ |
|
1127 | + public function update_status( $status = 'publish' ){ |
|
1128 | + |
|
1129 | + if ( $this->exists() && $this->get_status() != $status ) { |
|
1130 | + $this->set_status( $status ); |
|
1131 | + $this->save(); |
|
1132 | + } |
|
1133 | + |
|
1134 | + } |
|
1135 | + |
|
1136 | + /* |
|
1137 | 1137 | |-------------------------------------------------------------------------- |
1138 | 1138 | | Conditionals |
1139 | 1139 | |-------------------------------------------------------------------------- |
@@ -1142,290 +1142,290 @@ discard block |
||
1142 | 1142 | | |
1143 | 1143 | */ |
1144 | 1144 | |
1145 | - /** |
|
1146 | - * Checks whether a discount exists in the database or not |
|
1147 | - * |
|
1148 | - * @since 1.0.15 |
|
1149 | - */ |
|
1150 | - public function exists(){ |
|
1151 | - $id = $this->get_id(); |
|
1152 | - return ! empty( $id ); |
|
1153 | - } |
|
1154 | - |
|
1155 | - /** |
|
1156 | - * Checks the discount type. |
|
1157 | - * |
|
1158 | - * |
|
1159 | - * @param string $type the discount type to check against |
|
1160 | - * @since 1.0.15 |
|
1161 | - * @return bool |
|
1162 | - */ |
|
1163 | - public function is_type( $type ) { |
|
1164 | - return $this->get_type() == $type; |
|
1165 | - } |
|
1166 | - |
|
1167 | - /** |
|
1168 | - * Checks whether the discount is published or not |
|
1169 | - * |
|
1170 | - * @since 1.0.15 |
|
1171 | - * @return bool |
|
1172 | - */ |
|
1173 | - public function is_active() { |
|
1174 | - return $this->get_status() == 'publish'; |
|
1175 | - } |
|
1176 | - |
|
1177 | - /** |
|
1178 | - * Checks whether the discount has max uses |
|
1179 | - * |
|
1180 | - * @since 1.0.15 |
|
1181 | - * @return bool |
|
1182 | - */ |
|
1183 | - public function has_limit() { |
|
1184 | - $limit = $this->get_max_uses(); |
|
1185 | - return ! empty( $limit ); |
|
1186 | - } |
|
1187 | - |
|
1188 | - /** |
|
1189 | - * Checks whether the discount has ever been used. |
|
1190 | - * |
|
1191 | - * @since 1.0.15 |
|
1192 | - * @return bool |
|
1193 | - */ |
|
1194 | - public function has_uses() { |
|
1195 | - return $this->get_uses() > 0; |
|
1196 | - } |
|
1197 | - |
|
1198 | - /** |
|
1199 | - * Checks whether the discount is has exided the usage limit or not |
|
1200 | - * |
|
1201 | - * @since 1.0.15 |
|
1202 | - * @return bool |
|
1203 | - */ |
|
1204 | - public function has_exceeded_limit() { |
|
1205 | - |
|
1206 | - if ( ! $this->has_limit() || ! $this->has_uses() ) { |
|
1207 | - $exceeded = false ; |
|
1208 | - } else { |
|
1209 | - $exceeded = (int) $this->get_max_uses() <= $this->get_uses(); |
|
1210 | - } |
|
1211 | - |
|
1212 | - return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->get_id(), $this, $this->get_code() ); |
|
1213 | - } |
|
1214 | - |
|
1215 | - /** |
|
1216 | - * Checks whether the discount has an expiration date. |
|
1217 | - * |
|
1218 | - * @since 1.0.15 |
|
1219 | - * @return bool |
|
1220 | - */ |
|
1221 | - public function has_expiration_date() { |
|
1222 | - $date = $this->get_expiration_date(); |
|
1223 | - return ! empty( $date ); |
|
1224 | - } |
|
1225 | - |
|
1226 | - /** |
|
1227 | - * Checks if the discount is expired |
|
1228 | - * |
|
1229 | - * @since 1.0.15 |
|
1230 | - * @return bool |
|
1231 | - */ |
|
1232 | - public function is_expired() { |
|
1233 | - $expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false; |
|
1234 | - return apply_filters( 'wpinv_is_discount_expired', $expired, $this->get_id(), $this, $this->get_code() ); |
|
1235 | - } |
|
1236 | - |
|
1237 | - /** |
|
1238 | - * Checks whether the discount has a start date. |
|
1239 | - * |
|
1240 | - * @since 1.0.15 |
|
1241 | - * @return bool |
|
1242 | - */ |
|
1243 | - public function has_start_date() { |
|
1244 | - $date = $this->get_start_date(); |
|
1245 | - return ! empty( $date ); |
|
1246 | - } |
|
1247 | - |
|
1248 | - /** |
|
1249 | - * Checks the discount start date. |
|
1250 | - * |
|
1251 | - * @since 1.0.15 |
|
1252 | - * @return bool |
|
1253 | - */ |
|
1254 | - public function has_started() { |
|
1255 | - $started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() ); |
|
1256 | - return apply_filters( 'wpinv_is_discount_started', $started, $this->get_id(), $this, $this->get_code() ); |
|
1257 | - } |
|
1258 | - |
|
1259 | - /** |
|
1260 | - * Checks the discount has allowed items or not. |
|
1261 | - * |
|
1262 | - * @since 1.0.15 |
|
1263 | - * @return bool |
|
1264 | - */ |
|
1265 | - public function has_allowed_items() { |
|
1266 | - $allowed_items = $this->get_allowed_items(); |
|
1267 | - return ! empty( $allowed_items ); |
|
1268 | - } |
|
1269 | - |
|
1270 | - /** |
|
1271 | - * Checks the discount has excluded items or not. |
|
1272 | - * |
|
1273 | - * @since 1.0.15 |
|
1274 | - * @return bool |
|
1275 | - */ |
|
1276 | - public function has_excluded_items() { |
|
1277 | - $excluded_items = $this->get_excluded_items(); |
|
1278 | - return ! empty( $excluded_items ); |
|
1279 | - } |
|
1280 | - |
|
1281 | - /** |
|
1282 | - * Check if a discount is valid for a given item id. |
|
1283 | - * |
|
1284 | - * @param int|int[] $item_ids |
|
1285 | - * @since 1.0.15 |
|
1286 | - * @return boolean |
|
1287 | - */ |
|
1288 | - public function is_valid_for_items( $item_ids ) { |
|
1289 | - |
|
1290 | - $item_ids = array_filter( wp_parse_id_list( $item_ids ) ); |
|
1291 | - $included = array_intersect( $item_ids, $this->get_allowed_items() ); |
|
1292 | - $excluded = array_intersect( $item_ids, $this->get_excluded_items() ); |
|
1293 | - |
|
1294 | - if ( $this->has_excluded_items() && ! empty( $excluded ) ) { |
|
1295 | - return false; |
|
1296 | - } |
|
1297 | - |
|
1298 | - if ( $this->has_allowed_items() && empty( $included ) ) { |
|
1299 | - return false; |
|
1300 | - } |
|
1301 | - |
|
1302 | - return true; |
|
1303 | - } |
|
1304 | - |
|
1305 | - /** |
|
1306 | - * Checks the discount has required items or not. |
|
1307 | - * |
|
1308 | - * @since 1.0.15 |
|
1309 | - * @return bool |
|
1310 | - */ |
|
1311 | - public function has_required_items() { |
|
1312 | - $required_items = $this->get_required_items(); |
|
1313 | - return ! empty( $required_items ); |
|
1314 | - } |
|
1315 | - |
|
1316 | - /** |
|
1317 | - * Checks if the required items are met |
|
1318 | - * |
|
1319 | - * @param int|int[] $item_ids |
|
1320 | - * @since 1.0.15 |
|
1321 | - * @return boolean |
|
1322 | - */ |
|
1323 | - public function is_required_items_met( $item_ids ) { |
|
1324 | - |
|
1325 | - if ( ! $this->has_required_items() ) { |
|
1326 | - return true; |
|
1327 | - } |
|
1328 | - |
|
1329 | - return ! array_diff( $this->get_required_items(), array_filter( wp_parse_id_list( $item_ids ) ) ); |
|
1330 | - } |
|
1331 | - |
|
1332 | - /** |
|
1333 | - * Check if a discount is valid for the given amount |
|
1334 | - * |
|
1335 | - * @param float $amount The amount to check against |
|
1336 | - * @since 1.0.15 |
|
1337 | - * @return boolean |
|
1338 | - */ |
|
1339 | - public function is_valid_for_amount( $amount ) { |
|
1340 | - return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount ); |
|
1341 | - } |
|
1342 | - |
|
1343 | - /** |
|
1344 | - * Checks if the minimum amount is set |
|
1345 | - * |
|
1346 | - * @since 1.0.15 |
|
1347 | - * @return boolean |
|
1348 | - */ |
|
1349 | - public function has_minimum_amount() { |
|
1350 | - $minimum = $this->get_minimum_total(); |
|
1351 | - return ! empty( $minimum ); |
|
1352 | - } |
|
1353 | - |
|
1354 | - /** |
|
1355 | - * Checks if the minimum amount is met |
|
1356 | - * |
|
1357 | - * @param float $amount The amount to check against |
|
1358 | - * @since 1.0.15 |
|
1359 | - * @return boolean |
|
1360 | - */ |
|
1361 | - public function is_minimum_amount_met( $amount ) { |
|
1362 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1363 | - $min_met= ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) ); |
|
1364 | - return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1365 | - } |
|
1366 | - |
|
1367 | - /** |
|
1368 | - * Checks if the maximum amount is set |
|
1369 | - * |
|
1370 | - * @since 1.0.15 |
|
1371 | - * @return boolean |
|
1372 | - */ |
|
1373 | - public function has_maximum_amount() { |
|
1374 | - $maximum = $this->get_maximum_total(); |
|
1375 | - return ! empty( $maximum ); |
|
1376 | - } |
|
1377 | - |
|
1378 | - /** |
|
1379 | - * Checks if the maximum amount is met |
|
1380 | - * |
|
1381 | - * @param float $amount The amount to check against |
|
1382 | - * @since 1.0.15 |
|
1383 | - * @return boolean |
|
1384 | - */ |
|
1385 | - public function is_maximum_amount_met( $amount ) { |
|
1386 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1387 | - $max_met= ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) ); |
|
1388 | - return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1389 | - } |
|
1390 | - |
|
1391 | - /** |
|
1392 | - * Checks if the discount is recurring. |
|
1393 | - * |
|
1394 | - * @since 1.0.15 |
|
1395 | - * @return boolean |
|
1396 | - */ |
|
1397 | - public function is_recurring() { |
|
1398 | - $recurring = $this->get_is_recurring(); |
|
1399 | - return ! empty( $recurring ); |
|
1400 | - } |
|
1401 | - |
|
1402 | - /** |
|
1403 | - * Checks if the discount is single use. |
|
1404 | - * |
|
1405 | - * @since 1.0.15 |
|
1406 | - * @return boolean |
|
1407 | - */ |
|
1408 | - public function is_single_use() { |
|
1409 | - $usage = $this->get_is_single_use(); |
|
1410 | - return ! empty( $usage ); |
|
1411 | - } |
|
1412 | - |
|
1413 | - /** |
|
1414 | - * Check if a discount is valid for the given user |
|
1415 | - * |
|
1416 | - * @param int|string $user |
|
1417 | - * @since 1.0.15 |
|
1418 | - * @return boolean |
|
1419 | - */ |
|
1420 | - public function is_valid_for_user( $user ) { |
|
1421 | - |
|
1422 | - // Ensure that the discount is single use. |
|
1423 | - if ( empty( $user ) || ! $this->is_single_use() ) { |
|
1424 | - return true; |
|
1425 | - } |
|
1426 | - |
|
1427 | - // Prepare the user id. |
|
1428 | - $user_id = 0; |
|
1145 | + /** |
|
1146 | + * Checks whether a discount exists in the database or not |
|
1147 | + * |
|
1148 | + * @since 1.0.15 |
|
1149 | + */ |
|
1150 | + public function exists(){ |
|
1151 | + $id = $this->get_id(); |
|
1152 | + return ! empty( $id ); |
|
1153 | + } |
|
1154 | + |
|
1155 | + /** |
|
1156 | + * Checks the discount type. |
|
1157 | + * |
|
1158 | + * |
|
1159 | + * @param string $type the discount type to check against |
|
1160 | + * @since 1.0.15 |
|
1161 | + * @return bool |
|
1162 | + */ |
|
1163 | + public function is_type( $type ) { |
|
1164 | + return $this->get_type() == $type; |
|
1165 | + } |
|
1166 | + |
|
1167 | + /** |
|
1168 | + * Checks whether the discount is published or not |
|
1169 | + * |
|
1170 | + * @since 1.0.15 |
|
1171 | + * @return bool |
|
1172 | + */ |
|
1173 | + public function is_active() { |
|
1174 | + return $this->get_status() == 'publish'; |
|
1175 | + } |
|
1176 | + |
|
1177 | + /** |
|
1178 | + * Checks whether the discount has max uses |
|
1179 | + * |
|
1180 | + * @since 1.0.15 |
|
1181 | + * @return bool |
|
1182 | + */ |
|
1183 | + public function has_limit() { |
|
1184 | + $limit = $this->get_max_uses(); |
|
1185 | + return ! empty( $limit ); |
|
1186 | + } |
|
1187 | + |
|
1188 | + /** |
|
1189 | + * Checks whether the discount has ever been used. |
|
1190 | + * |
|
1191 | + * @since 1.0.15 |
|
1192 | + * @return bool |
|
1193 | + */ |
|
1194 | + public function has_uses() { |
|
1195 | + return $this->get_uses() > 0; |
|
1196 | + } |
|
1197 | + |
|
1198 | + /** |
|
1199 | + * Checks whether the discount is has exided the usage limit or not |
|
1200 | + * |
|
1201 | + * @since 1.0.15 |
|
1202 | + * @return bool |
|
1203 | + */ |
|
1204 | + public function has_exceeded_limit() { |
|
1205 | + |
|
1206 | + if ( ! $this->has_limit() || ! $this->has_uses() ) { |
|
1207 | + $exceeded = false ; |
|
1208 | + } else { |
|
1209 | + $exceeded = (int) $this->get_max_uses() <= $this->get_uses(); |
|
1210 | + } |
|
1211 | + |
|
1212 | + return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->get_id(), $this, $this->get_code() ); |
|
1213 | + } |
|
1214 | + |
|
1215 | + /** |
|
1216 | + * Checks whether the discount has an expiration date. |
|
1217 | + * |
|
1218 | + * @since 1.0.15 |
|
1219 | + * @return bool |
|
1220 | + */ |
|
1221 | + public function has_expiration_date() { |
|
1222 | + $date = $this->get_expiration_date(); |
|
1223 | + return ! empty( $date ); |
|
1224 | + } |
|
1225 | + |
|
1226 | + /** |
|
1227 | + * Checks if the discount is expired |
|
1228 | + * |
|
1229 | + * @since 1.0.15 |
|
1230 | + * @return bool |
|
1231 | + */ |
|
1232 | + public function is_expired() { |
|
1233 | + $expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false; |
|
1234 | + return apply_filters( 'wpinv_is_discount_expired', $expired, $this->get_id(), $this, $this->get_code() ); |
|
1235 | + } |
|
1236 | + |
|
1237 | + /** |
|
1238 | + * Checks whether the discount has a start date. |
|
1239 | + * |
|
1240 | + * @since 1.0.15 |
|
1241 | + * @return bool |
|
1242 | + */ |
|
1243 | + public function has_start_date() { |
|
1244 | + $date = $this->get_start_date(); |
|
1245 | + return ! empty( $date ); |
|
1246 | + } |
|
1247 | + |
|
1248 | + /** |
|
1249 | + * Checks the discount start date. |
|
1250 | + * |
|
1251 | + * @since 1.0.15 |
|
1252 | + * @return bool |
|
1253 | + */ |
|
1254 | + public function has_started() { |
|
1255 | + $started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() ); |
|
1256 | + return apply_filters( 'wpinv_is_discount_started', $started, $this->get_id(), $this, $this->get_code() ); |
|
1257 | + } |
|
1258 | + |
|
1259 | + /** |
|
1260 | + * Checks the discount has allowed items or not. |
|
1261 | + * |
|
1262 | + * @since 1.0.15 |
|
1263 | + * @return bool |
|
1264 | + */ |
|
1265 | + public function has_allowed_items() { |
|
1266 | + $allowed_items = $this->get_allowed_items(); |
|
1267 | + return ! empty( $allowed_items ); |
|
1268 | + } |
|
1269 | + |
|
1270 | + /** |
|
1271 | + * Checks the discount has excluded items or not. |
|
1272 | + * |
|
1273 | + * @since 1.0.15 |
|
1274 | + * @return bool |
|
1275 | + */ |
|
1276 | + public function has_excluded_items() { |
|
1277 | + $excluded_items = $this->get_excluded_items(); |
|
1278 | + return ! empty( $excluded_items ); |
|
1279 | + } |
|
1280 | + |
|
1281 | + /** |
|
1282 | + * Check if a discount is valid for a given item id. |
|
1283 | + * |
|
1284 | + * @param int|int[] $item_ids |
|
1285 | + * @since 1.0.15 |
|
1286 | + * @return boolean |
|
1287 | + */ |
|
1288 | + public function is_valid_for_items( $item_ids ) { |
|
1289 | + |
|
1290 | + $item_ids = array_filter( wp_parse_id_list( $item_ids ) ); |
|
1291 | + $included = array_intersect( $item_ids, $this->get_allowed_items() ); |
|
1292 | + $excluded = array_intersect( $item_ids, $this->get_excluded_items() ); |
|
1293 | + |
|
1294 | + if ( $this->has_excluded_items() && ! empty( $excluded ) ) { |
|
1295 | + return false; |
|
1296 | + } |
|
1297 | + |
|
1298 | + if ( $this->has_allowed_items() && empty( $included ) ) { |
|
1299 | + return false; |
|
1300 | + } |
|
1301 | + |
|
1302 | + return true; |
|
1303 | + } |
|
1304 | + |
|
1305 | + /** |
|
1306 | + * Checks the discount has required items or not. |
|
1307 | + * |
|
1308 | + * @since 1.0.15 |
|
1309 | + * @return bool |
|
1310 | + */ |
|
1311 | + public function has_required_items() { |
|
1312 | + $required_items = $this->get_required_items(); |
|
1313 | + return ! empty( $required_items ); |
|
1314 | + } |
|
1315 | + |
|
1316 | + /** |
|
1317 | + * Checks if the required items are met |
|
1318 | + * |
|
1319 | + * @param int|int[] $item_ids |
|
1320 | + * @since 1.0.15 |
|
1321 | + * @return boolean |
|
1322 | + */ |
|
1323 | + public function is_required_items_met( $item_ids ) { |
|
1324 | + |
|
1325 | + if ( ! $this->has_required_items() ) { |
|
1326 | + return true; |
|
1327 | + } |
|
1328 | + |
|
1329 | + return ! array_diff( $this->get_required_items(), array_filter( wp_parse_id_list( $item_ids ) ) ); |
|
1330 | + } |
|
1331 | + |
|
1332 | + /** |
|
1333 | + * Check if a discount is valid for the given amount |
|
1334 | + * |
|
1335 | + * @param float $amount The amount to check against |
|
1336 | + * @since 1.0.15 |
|
1337 | + * @return boolean |
|
1338 | + */ |
|
1339 | + public function is_valid_for_amount( $amount ) { |
|
1340 | + return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount ); |
|
1341 | + } |
|
1342 | + |
|
1343 | + /** |
|
1344 | + * Checks if the minimum amount is set |
|
1345 | + * |
|
1346 | + * @since 1.0.15 |
|
1347 | + * @return boolean |
|
1348 | + */ |
|
1349 | + public function has_minimum_amount() { |
|
1350 | + $minimum = $this->get_minimum_total(); |
|
1351 | + return ! empty( $minimum ); |
|
1352 | + } |
|
1353 | + |
|
1354 | + /** |
|
1355 | + * Checks if the minimum amount is met |
|
1356 | + * |
|
1357 | + * @param float $amount The amount to check against |
|
1358 | + * @since 1.0.15 |
|
1359 | + * @return boolean |
|
1360 | + */ |
|
1361 | + public function is_minimum_amount_met( $amount ) { |
|
1362 | + $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1363 | + $min_met= ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) ); |
|
1364 | + return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1365 | + } |
|
1366 | + |
|
1367 | + /** |
|
1368 | + * Checks if the maximum amount is set |
|
1369 | + * |
|
1370 | + * @since 1.0.15 |
|
1371 | + * @return boolean |
|
1372 | + */ |
|
1373 | + public function has_maximum_amount() { |
|
1374 | + $maximum = $this->get_maximum_total(); |
|
1375 | + return ! empty( $maximum ); |
|
1376 | + } |
|
1377 | + |
|
1378 | + /** |
|
1379 | + * Checks if the maximum amount is met |
|
1380 | + * |
|
1381 | + * @param float $amount The amount to check against |
|
1382 | + * @since 1.0.15 |
|
1383 | + * @return boolean |
|
1384 | + */ |
|
1385 | + public function is_maximum_amount_met( $amount ) { |
|
1386 | + $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1387 | + $max_met= ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) ); |
|
1388 | + return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1389 | + } |
|
1390 | + |
|
1391 | + /** |
|
1392 | + * Checks if the discount is recurring. |
|
1393 | + * |
|
1394 | + * @since 1.0.15 |
|
1395 | + * @return boolean |
|
1396 | + */ |
|
1397 | + public function is_recurring() { |
|
1398 | + $recurring = $this->get_is_recurring(); |
|
1399 | + return ! empty( $recurring ); |
|
1400 | + } |
|
1401 | + |
|
1402 | + /** |
|
1403 | + * Checks if the discount is single use. |
|
1404 | + * |
|
1405 | + * @since 1.0.15 |
|
1406 | + * @return boolean |
|
1407 | + */ |
|
1408 | + public function is_single_use() { |
|
1409 | + $usage = $this->get_is_single_use(); |
|
1410 | + return ! empty( $usage ); |
|
1411 | + } |
|
1412 | + |
|
1413 | + /** |
|
1414 | + * Check if a discount is valid for the given user |
|
1415 | + * |
|
1416 | + * @param int|string $user |
|
1417 | + * @since 1.0.15 |
|
1418 | + * @return boolean |
|
1419 | + */ |
|
1420 | + public function is_valid_for_user( $user ) { |
|
1421 | + |
|
1422 | + // Ensure that the discount is single use. |
|
1423 | + if ( empty( $user ) || ! $this->is_single_use() ) { |
|
1424 | + return true; |
|
1425 | + } |
|
1426 | + |
|
1427 | + // Prepare the user id. |
|
1428 | + $user_id = 0; |
|
1429 | 1429 | if ( is_numeric( $user ) ) { |
1430 | 1430 | $user_id = absint( $user ); |
1431 | 1431 | } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
@@ -1434,117 +1434,117 @@ discard block |
||
1434 | 1434 | $user_id = $user_data->ID; |
1435 | 1435 | } |
1436 | 1436 | |
1437 | - // Ensure that we have a user. |
|
1438 | - if ( empty( $user_id ) ) { |
|
1439 | - return true; |
|
1440 | - } |
|
1437 | + // Ensure that we have a user. |
|
1438 | + if ( empty( $user_id ) ) { |
|
1439 | + return true; |
|
1440 | + } |
|
1441 | 1441 | |
1442 | - // Get all payments with matching user id. |
|
1442 | + // Get all payments with matching user id. |
|
1443 | 1443 | $payments = wpinv_get_invoices( array( 'user' => $user_id, 'limit' => false, 'paginate' => false ) ); |
1444 | - $code = strtolower( $this->get_code() ); |
|
1445 | - |
|
1446 | - // For each payment... |
|
1447 | - foreach ( $payments as $payment ) { |
|
1448 | - |
|
1449 | - // Only check for paid invoices. |
|
1450 | - if ( $payment->is_paid() && strtolower( $payment->get_discount_code() ) == $code ) { |
|
1451 | - return false; |
|
1452 | - } |
|
1453 | - |
|
1454 | - } |
|
1455 | - |
|
1456 | - return true; |
|
1457 | - } |
|
1458 | - |
|
1459 | - /** |
|
1460 | - * Deletes the discount from the database |
|
1461 | - * |
|
1462 | - * @since 1.0.15 |
|
1463 | - * @return boolean |
|
1464 | - */ |
|
1465 | - public function remove() { |
|
1466 | - return $this->delete(); |
|
1467 | - } |
|
1468 | - |
|
1469 | - /** |
|
1470 | - * Increases a discount's usage. |
|
1471 | - * |
|
1472 | - * @since 1.0.15 |
|
1473 | - * @param int $by The number of usages to increas by. |
|
1474 | - * @return int |
|
1475 | - */ |
|
1476 | - public function increase_usage( $by = 1 ) { |
|
1477 | - |
|
1478 | - // Abort if zero. |
|
1479 | - if ( empty( $by ) ) { |
|
1480 | - return; |
|
1481 | - } |
|
1482 | - |
|
1483 | - // Increase the usage. |
|
1484 | - $this->set_uses( $this->get_uses() + (int) $by ); |
|
1485 | - |
|
1486 | - // Save the discount. |
|
1487 | - $this->save(); |
|
1488 | - |
|
1489 | - // Fire relevant hooks. |
|
1490 | - if( (int) $by > 0 ) { |
|
1491 | - do_action( 'wpinv_discount_increase_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1492 | - } else { |
|
1493 | - do_action( 'wpinv_discount_decrease_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1494 | - } |
|
1495 | - |
|
1496 | - // Return the number of times the discount has been used. |
|
1497 | - return $this->get_uses(); |
|
1498 | - } |
|
1499 | - |
|
1500 | - /** |
|
1501 | - * Alias of self::__toString() |
|
1502 | - * |
|
1503 | - * @since 1.0.15 |
|
1504 | - * @return string|false |
|
1505 | - */ |
|
1506 | - public function get_data_as_json() { |
|
1507 | - return $this->__toString(); |
|
1508 | - } |
|
1509 | - |
|
1510 | - /** |
|
1511 | - * Returns a discount's discounted amount. |
|
1512 | - * |
|
1513 | - * @since 1.0.15 |
|
1514 | - * @param float $amount |
|
1515 | - * @return float |
|
1516 | - */ |
|
1517 | - public function get_discounted_amount( $amount ) { |
|
1518 | - |
|
1519 | - // Convert amount to float. |
|
1520 | - $amount = (float) $amount; |
|
1521 | - |
|
1522 | - // Get discount amount. |
|
1523 | - $discount_amount = $this->get_amount(); |
|
1524 | - |
|
1525 | - if ( empty( $discount_amount ) ) { |
|
1526 | - return 0; |
|
1527 | - } |
|
1528 | - |
|
1529 | - // Format the amount. |
|
1530 | - $discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) ); |
|
1531 | - |
|
1532 | - // If this is a percentage discount. |
|
1533 | - if ( $this->is_type( 'percent' ) ) { |
|
1444 | + $code = strtolower( $this->get_code() ); |
|
1445 | + |
|
1446 | + // For each payment... |
|
1447 | + foreach ( $payments as $payment ) { |
|
1448 | + |
|
1449 | + // Only check for paid invoices. |
|
1450 | + if ( $payment->is_paid() && strtolower( $payment->get_discount_code() ) == $code ) { |
|
1451 | + return false; |
|
1452 | + } |
|
1453 | + |
|
1454 | + } |
|
1455 | + |
|
1456 | + return true; |
|
1457 | + } |
|
1458 | + |
|
1459 | + /** |
|
1460 | + * Deletes the discount from the database |
|
1461 | + * |
|
1462 | + * @since 1.0.15 |
|
1463 | + * @return boolean |
|
1464 | + */ |
|
1465 | + public function remove() { |
|
1466 | + return $this->delete(); |
|
1467 | + } |
|
1468 | + |
|
1469 | + /** |
|
1470 | + * Increases a discount's usage. |
|
1471 | + * |
|
1472 | + * @since 1.0.15 |
|
1473 | + * @param int $by The number of usages to increas by. |
|
1474 | + * @return int |
|
1475 | + */ |
|
1476 | + public function increase_usage( $by = 1 ) { |
|
1477 | + |
|
1478 | + // Abort if zero. |
|
1479 | + if ( empty( $by ) ) { |
|
1480 | + return; |
|
1481 | + } |
|
1482 | + |
|
1483 | + // Increase the usage. |
|
1484 | + $this->set_uses( $this->get_uses() + (int) $by ); |
|
1485 | + |
|
1486 | + // Save the discount. |
|
1487 | + $this->save(); |
|
1488 | + |
|
1489 | + // Fire relevant hooks. |
|
1490 | + if( (int) $by > 0 ) { |
|
1491 | + do_action( 'wpinv_discount_increase_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1492 | + } else { |
|
1493 | + do_action( 'wpinv_discount_decrease_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1494 | + } |
|
1495 | + |
|
1496 | + // Return the number of times the discount has been used. |
|
1497 | + return $this->get_uses(); |
|
1498 | + } |
|
1499 | + |
|
1500 | + /** |
|
1501 | + * Alias of self::__toString() |
|
1502 | + * |
|
1503 | + * @since 1.0.15 |
|
1504 | + * @return string|false |
|
1505 | + */ |
|
1506 | + public function get_data_as_json() { |
|
1507 | + return $this->__toString(); |
|
1508 | + } |
|
1509 | + |
|
1510 | + /** |
|
1511 | + * Returns a discount's discounted amount. |
|
1512 | + * |
|
1513 | + * @since 1.0.15 |
|
1514 | + * @param float $amount |
|
1515 | + * @return float |
|
1516 | + */ |
|
1517 | + public function get_discounted_amount( $amount ) { |
|
1518 | + |
|
1519 | + // Convert amount to float. |
|
1520 | + $amount = (float) $amount; |
|
1521 | + |
|
1522 | + // Get discount amount. |
|
1523 | + $discount_amount = $this->get_amount(); |
|
1524 | + |
|
1525 | + if ( empty( $discount_amount ) ) { |
|
1526 | + return 0; |
|
1527 | + } |
|
1528 | + |
|
1529 | + // Format the amount. |
|
1530 | + $discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) ); |
|
1531 | + |
|
1532 | + // If this is a percentage discount. |
|
1533 | + if ( $this->is_type( 'percent' ) ) { |
|
1534 | 1534 | $discount_amount = $amount * ( $discount_amount / 100 ); |
1535 | - } |
|
1535 | + } |
|
1536 | 1536 | |
1537 | - // Discount can not be less than zero... |
|
1538 | - if ( $discount_amount < 0 ) { |
|
1539 | - $discount_amount = 0; |
|
1540 | - } |
|
1537 | + // Discount can not be less than zero... |
|
1538 | + if ( $discount_amount < 0 ) { |
|
1539 | + $discount_amount = 0; |
|
1540 | + } |
|
1541 | 1541 | |
1542 | - // ... or more than the amount. |
|
1543 | - if ( $discount_amount > $amount ) { |
|
1544 | - $discount_amount = $amount; |
|
1545 | - } |
|
1542 | + // ... or more than the amount. |
|
1543 | + if ( $discount_amount > $amount ) { |
|
1544 | + $discount_amount = $amount; |
|
1545 | + } |
|
1546 | 1546 | |
1547 | - return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this ); |
|
1548 | - } |
|
1547 | + return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this ); |
|
1548 | + } |
|
1549 | 1549 | |
1550 | 1550 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,198 +15,198 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Discount_Data_Store extends GetPaid_Data_Store_WP { |
17 | 17 | |
18 | - /** |
|
19 | - * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | - * |
|
21 | - * @since 1.0.19 |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $internal_meta_keys = array( |
|
25 | - '_wpi_discount_code', |
|
26 | - '_wpi_discount_amount', |
|
27 | - '_wpi_discount_start', |
|
28 | - '_wpi_discount_expiration', |
|
29 | - '_wpi_discount_type', |
|
30 | - '_wpi_discount_uses', |
|
31 | - '_wpi_discount_is_single_use', |
|
32 | - '_wpi_discount_items', |
|
33 | - '_wpi_discount_excluded_items', |
|
34 | - '_wpi_discount_required_items', |
|
35 | - '_wpi_discount_max_uses', |
|
36 | - '_wpi_discount_is_recurring', |
|
37 | - '_wpi_discount_min_total', |
|
38 | - '_wpi_discount_max_total', |
|
39 | - ); |
|
40 | - |
|
41 | - /** |
|
42 | - * A map of meta keys to data props. |
|
43 | - * |
|
44 | - * @since 1.0.19 |
|
45 | - * |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - protected $meta_key_to_props = array( |
|
49 | - '_wpi_discount_code' => 'code', |
|
50 | - '_wpi_discount_amount' => 'amount', |
|
51 | - '_wpi_discount_start' => 'start', |
|
52 | - '_wpi_discount_expiration' => 'expiration', |
|
53 | - '_wpi_discount_type' => 'type', |
|
54 | - '_wpi_discount_uses' => 'uses', |
|
55 | - '_wpi_discount_is_single_use' => 'is_single_use', |
|
56 | - '_wpi_discount_items' => 'items', |
|
57 | - '_wpi_discount_excluded_items' => 'excluded_items', |
|
58 | - '_wpi_discount_required_items' => 'required_items', |
|
59 | - '_wpi_discount_max_uses' => 'max_uses', |
|
60 | - '_wpi_discount_is_recurring' => 'is_recurring', |
|
61 | - '_wpi_discount_min_total' => 'min_total', |
|
62 | - '_wpi_discount_max_total' => 'max_total', |
|
63 | - ); |
|
64 | - |
|
65 | - /* |
|
18 | + /** |
|
19 | + * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | + * |
|
21 | + * @since 1.0.19 |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $internal_meta_keys = array( |
|
25 | + '_wpi_discount_code', |
|
26 | + '_wpi_discount_amount', |
|
27 | + '_wpi_discount_start', |
|
28 | + '_wpi_discount_expiration', |
|
29 | + '_wpi_discount_type', |
|
30 | + '_wpi_discount_uses', |
|
31 | + '_wpi_discount_is_single_use', |
|
32 | + '_wpi_discount_items', |
|
33 | + '_wpi_discount_excluded_items', |
|
34 | + '_wpi_discount_required_items', |
|
35 | + '_wpi_discount_max_uses', |
|
36 | + '_wpi_discount_is_recurring', |
|
37 | + '_wpi_discount_min_total', |
|
38 | + '_wpi_discount_max_total', |
|
39 | + ); |
|
40 | + |
|
41 | + /** |
|
42 | + * A map of meta keys to data props. |
|
43 | + * |
|
44 | + * @since 1.0.19 |
|
45 | + * |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + protected $meta_key_to_props = array( |
|
49 | + '_wpi_discount_code' => 'code', |
|
50 | + '_wpi_discount_amount' => 'amount', |
|
51 | + '_wpi_discount_start' => 'start', |
|
52 | + '_wpi_discount_expiration' => 'expiration', |
|
53 | + '_wpi_discount_type' => 'type', |
|
54 | + '_wpi_discount_uses' => 'uses', |
|
55 | + '_wpi_discount_is_single_use' => 'is_single_use', |
|
56 | + '_wpi_discount_items' => 'items', |
|
57 | + '_wpi_discount_excluded_items' => 'excluded_items', |
|
58 | + '_wpi_discount_required_items' => 'required_items', |
|
59 | + '_wpi_discount_max_uses' => 'max_uses', |
|
60 | + '_wpi_discount_is_recurring' => 'is_recurring', |
|
61 | + '_wpi_discount_min_total' => 'min_total', |
|
62 | + '_wpi_discount_max_total' => 'max_total', |
|
63 | + ); |
|
64 | + |
|
65 | + /* |
|
66 | 66 | |-------------------------------------------------------------------------- |
67 | 67 | | CRUD Methods |
68 | 68 | |-------------------------------------------------------------------------- |
69 | 69 | */ |
70 | 70 | |
71 | - /** |
|
72 | - * Method to create a new discount in the database. |
|
73 | - * |
|
74 | - * @param WPInv_Discount $discount Discount object. |
|
75 | - */ |
|
76 | - public function create( &$discount ) { |
|
77 | - $discount->set_version( WPINV_VERSION ); |
|
78 | - $discount->set_date_created( current_time('mysql') ); |
|
79 | - |
|
80 | - // Create a new post. |
|
81 | - $id = wp_insert_post( |
|
82 | - apply_filters( |
|
83 | - 'getpaid_new_discount_data', |
|
84 | - array( |
|
85 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
86 | - 'post_type' => 'wpi_discount', |
|
87 | - 'post_status' => $this->get_post_status( $discount ), |
|
88 | - 'ping_status' => 'closed', |
|
89 | - 'post_author' => $discount->get_author( 'edit' ), |
|
90 | - 'post_title' => $discount->get_name( 'edit' ), |
|
91 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
92 | - ) |
|
93 | - ), |
|
94 | - true |
|
95 | - ); |
|
96 | - |
|
97 | - if ( $id && ! is_wp_error( $id ) ) { |
|
98 | - $discount->set_id( $id ); |
|
99 | - $this->update_post_meta( $discount ); |
|
100 | - $discount->save_meta_data(); |
|
101 | - $discount->apply_changes(); |
|
102 | - $this->clear_caches( $discount ); |
|
103 | - do_action( 'getpaid_new_discount', $discount ); |
|
104 | - return true; |
|
105 | - } |
|
106 | - |
|
107 | - if ( is_wp_error( $id ) ) { |
|
108 | - $discount->last_error = $id->get_error_message(); |
|
109 | - } |
|
110 | - |
|
111 | - return false; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Method to read a discount from the database. |
|
116 | - * |
|
117 | - * @param WPInv_Discount $discount Discount object. |
|
118 | - * |
|
119 | - */ |
|
120 | - public function read( &$discount ) { |
|
121 | - |
|
122 | - $discount->set_defaults(); |
|
123 | - $discount_object = get_post( $discount->get_id() ); |
|
124 | - |
|
125 | - if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) { |
|
126 | - $discount->last_error = __( 'Invalid discount.', 'invoicing' ); |
|
127 | - $discount->set_id( 0 ); |
|
128 | - return false; |
|
129 | - } |
|
130 | - |
|
131 | - $discount->set_props( |
|
132 | - array( |
|
133 | - 'date_created' => 0 < $discount_object->post_date ? $discount_object->post_date : null, |
|
134 | - 'date_modified' => 0 < $discount_object->post_modified ? $discount_object->post_modified : null, |
|
135 | - 'status' => $discount_object->post_status, |
|
136 | - 'name' => $discount_object->post_title, |
|
137 | - 'author' => $discount_object->post_author, |
|
138 | - 'description' => $discount_object->post_excerpt, |
|
139 | - ) |
|
140 | - ); |
|
141 | - |
|
142 | - $this->read_object_data( $discount, $discount_object ); |
|
143 | - $discount->read_meta_data(); |
|
144 | - $discount->set_object_read( true ); |
|
145 | - do_action( 'getpaid_read_discount', $discount ); |
|
146 | - |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Method to update a discount in the database. |
|
151 | - * |
|
152 | - * @param WPInv_Discount $discount Discount object. |
|
153 | - */ |
|
154 | - public function update( &$discount ) { |
|
155 | - $discount->save_meta_data(); |
|
156 | - $discount->set_version( WPINV_VERSION ); |
|
157 | - |
|
158 | - if ( null === $discount->get_date_created( 'edit' ) ) { |
|
159 | - $discount->set_date_created( current_time('mysql') ); |
|
160 | - } |
|
161 | - |
|
162 | - // Grab the current status so we can compare. |
|
163 | - $previous_status = get_post_status( $discount->get_id() ); |
|
164 | - |
|
165 | - $changes = $discount->get_changes(); |
|
166 | - |
|
167 | - // Only update the post when the post data changes. |
|
168 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
169 | - $post_data = array( |
|
170 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
171 | - 'post_status' => $discount->get_status( 'edit' ), |
|
172 | - 'post_title' => $discount->get_name( 'edit' ), |
|
173 | - 'post_author' => $discount->get_author( 'edit' ), |
|
174 | - 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
175 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
176 | - ); |
|
177 | - |
|
178 | - /** |
|
179 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
180 | - * to update data, since wp_update_post spawns more calls to the |
|
181 | - * save_post action. |
|
182 | - * |
|
183 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
184 | - * or an update purely from CRUD. |
|
185 | - */ |
|
186 | - if ( doing_action( 'save_post' ) ) { |
|
187 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
188 | - clean_post_cache( $discount->get_id() ); |
|
189 | - } else { |
|
190 | - wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
191 | - } |
|
192 | - $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
193 | - } |
|
194 | - $this->update_post_meta( $discount ); |
|
195 | - $discount->apply_changes(); |
|
196 | - $this->clear_caches( $discount ); |
|
197 | - |
|
198 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
199 | - $new_status = $discount->get_status( 'edit' ); |
|
200 | - |
|
201 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
202 | - do_action( 'getpaid_new_discount', $discount ); |
|
203 | - } else { |
|
204 | - do_action( 'getpaid_update_discount', $discount ); |
|
205 | - } |
|
206 | - |
|
207 | - } |
|
208 | - |
|
209 | - /* |
|
71 | + /** |
|
72 | + * Method to create a new discount in the database. |
|
73 | + * |
|
74 | + * @param WPInv_Discount $discount Discount object. |
|
75 | + */ |
|
76 | + public function create( &$discount ) { |
|
77 | + $discount->set_version( WPINV_VERSION ); |
|
78 | + $discount->set_date_created( current_time('mysql') ); |
|
79 | + |
|
80 | + // Create a new post. |
|
81 | + $id = wp_insert_post( |
|
82 | + apply_filters( |
|
83 | + 'getpaid_new_discount_data', |
|
84 | + array( |
|
85 | + 'post_date' => $discount->get_date_created( 'edit' ), |
|
86 | + 'post_type' => 'wpi_discount', |
|
87 | + 'post_status' => $this->get_post_status( $discount ), |
|
88 | + 'ping_status' => 'closed', |
|
89 | + 'post_author' => $discount->get_author( 'edit' ), |
|
90 | + 'post_title' => $discount->get_name( 'edit' ), |
|
91 | + 'post_excerpt' => $discount->get_description( 'edit' ), |
|
92 | + ) |
|
93 | + ), |
|
94 | + true |
|
95 | + ); |
|
96 | + |
|
97 | + if ( $id && ! is_wp_error( $id ) ) { |
|
98 | + $discount->set_id( $id ); |
|
99 | + $this->update_post_meta( $discount ); |
|
100 | + $discount->save_meta_data(); |
|
101 | + $discount->apply_changes(); |
|
102 | + $this->clear_caches( $discount ); |
|
103 | + do_action( 'getpaid_new_discount', $discount ); |
|
104 | + return true; |
|
105 | + } |
|
106 | + |
|
107 | + if ( is_wp_error( $id ) ) { |
|
108 | + $discount->last_error = $id->get_error_message(); |
|
109 | + } |
|
110 | + |
|
111 | + return false; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Method to read a discount from the database. |
|
116 | + * |
|
117 | + * @param WPInv_Discount $discount Discount object. |
|
118 | + * |
|
119 | + */ |
|
120 | + public function read( &$discount ) { |
|
121 | + |
|
122 | + $discount->set_defaults(); |
|
123 | + $discount_object = get_post( $discount->get_id() ); |
|
124 | + |
|
125 | + if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) { |
|
126 | + $discount->last_error = __( 'Invalid discount.', 'invoicing' ); |
|
127 | + $discount->set_id( 0 ); |
|
128 | + return false; |
|
129 | + } |
|
130 | + |
|
131 | + $discount->set_props( |
|
132 | + array( |
|
133 | + 'date_created' => 0 < $discount_object->post_date ? $discount_object->post_date : null, |
|
134 | + 'date_modified' => 0 < $discount_object->post_modified ? $discount_object->post_modified : null, |
|
135 | + 'status' => $discount_object->post_status, |
|
136 | + 'name' => $discount_object->post_title, |
|
137 | + 'author' => $discount_object->post_author, |
|
138 | + 'description' => $discount_object->post_excerpt, |
|
139 | + ) |
|
140 | + ); |
|
141 | + |
|
142 | + $this->read_object_data( $discount, $discount_object ); |
|
143 | + $discount->read_meta_data(); |
|
144 | + $discount->set_object_read( true ); |
|
145 | + do_action( 'getpaid_read_discount', $discount ); |
|
146 | + |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Method to update a discount in the database. |
|
151 | + * |
|
152 | + * @param WPInv_Discount $discount Discount object. |
|
153 | + */ |
|
154 | + public function update( &$discount ) { |
|
155 | + $discount->save_meta_data(); |
|
156 | + $discount->set_version( WPINV_VERSION ); |
|
157 | + |
|
158 | + if ( null === $discount->get_date_created( 'edit' ) ) { |
|
159 | + $discount->set_date_created( current_time('mysql') ); |
|
160 | + } |
|
161 | + |
|
162 | + // Grab the current status so we can compare. |
|
163 | + $previous_status = get_post_status( $discount->get_id() ); |
|
164 | + |
|
165 | + $changes = $discount->get_changes(); |
|
166 | + |
|
167 | + // Only update the post when the post data changes. |
|
168 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
169 | + $post_data = array( |
|
170 | + 'post_date' => $discount->get_date_created( 'edit' ), |
|
171 | + 'post_status' => $discount->get_status( 'edit' ), |
|
172 | + 'post_title' => $discount->get_name( 'edit' ), |
|
173 | + 'post_author' => $discount->get_author( 'edit' ), |
|
174 | + 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
175 | + 'post_excerpt' => $discount->get_description( 'edit' ), |
|
176 | + ); |
|
177 | + |
|
178 | + /** |
|
179 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
180 | + * to update data, since wp_update_post spawns more calls to the |
|
181 | + * save_post action. |
|
182 | + * |
|
183 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
184 | + * or an update purely from CRUD. |
|
185 | + */ |
|
186 | + if ( doing_action( 'save_post' ) ) { |
|
187 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
188 | + clean_post_cache( $discount->get_id() ); |
|
189 | + } else { |
|
190 | + wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
191 | + } |
|
192 | + $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
193 | + } |
|
194 | + $this->update_post_meta( $discount ); |
|
195 | + $discount->apply_changes(); |
|
196 | + $this->clear_caches( $discount ); |
|
197 | + |
|
198 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
199 | + $new_status = $discount->get_status( 'edit' ); |
|
200 | + |
|
201 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
202 | + do_action( 'getpaid_new_discount', $discount ); |
|
203 | + } else { |
|
204 | + do_action( 'getpaid_update_discount', $discount ); |
|
205 | + } |
|
206 | + |
|
207 | + } |
|
208 | + |
|
209 | + /* |
|
210 | 210 | |-------------------------------------------------------------------------- |
211 | 211 | | Additional Methods |
212 | 212 | |-------------------------------------------------------------------------- |
@@ -13,720 +13,720 @@ discard block |
||
13 | 13 | class GetPaid_Post_Types_Admin { |
14 | 14 | |
15 | 15 | /** |
16 | - * Hook in methods. |
|
17 | - */ |
|
18 | - public static function init() { |
|
19 | - |
|
20 | - // Init metaboxes. |
|
21 | - GetPaid_Metaboxes::init(); |
|
22 | - |
|
23 | - // Filter the post updated messages. |
|
24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
25 | - |
|
26 | - // Filter post actions. |
|
27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
29 | - |
|
30 | - // Invoice table columns. |
|
31 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
32 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
33 | - add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
34 | - add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
35 | - |
|
36 | - // Items table columns. |
|
37 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
38 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
39 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
40 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
41 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
42 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
43 | - |
|
44 | - // Payment forms columns. |
|
45 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
46 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
47 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
48 | - |
|
49 | - // Discount table columns. |
|
50 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
51 | - add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
52 | - |
|
53 | - // Deleting posts. |
|
54 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
55 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
56 | - |
|
57 | - add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Post updated messages. |
|
62 | - */ |
|
63 | - public static function post_updated_messages( $messages ) { |
|
64 | - global $post; |
|
65 | - |
|
66 | - $messages['wpi_discount'] = array( |
|
67 | - 0 => '', |
|
68 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
69 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
70 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
71 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
72 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
73 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
74 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
75 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
76 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
77 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
78 | - ); |
|
79 | - |
|
80 | - $messages['wpi_payment_form'] = array( |
|
81 | - 0 => '', |
|
82 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
84 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
85 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
86 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
87 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
88 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
89 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
90 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
91 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
92 | - ); |
|
93 | - |
|
94 | - return $messages; |
|
95 | - |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Post row actions. |
|
100 | - */ |
|
101 | - public static function post_row_actions( $actions, $post ) { |
|
102 | - |
|
103 | - $post = get_post( $post ); |
|
104 | - |
|
105 | - // We do not want to edit the default payment form. |
|
106 | - if ( 'wpi_payment_form' == $post->post_type ) { |
|
107 | - |
|
108 | - if ( $post->ID == wpinv_get_default_payment_form() ) { |
|
109 | - unset( $actions['trash'] ); |
|
110 | - unset( $actions['inline hide-if-no-js'] ); |
|
111 | - } |
|
112 | - |
|
113 | - $actions['duplicate'] = sprintf( |
|
114 | - '<a href="%1$s">%2$s</a>', |
|
115 | - esc_url( |
|
116 | - wp_nonce_url( |
|
117 | - add_query_arg( |
|
118 | - array( |
|
119 | - 'getpaid-admin-action' => 'duplicate_form', |
|
120 | - 'form_id' => $post->ID |
|
121 | - ) |
|
122 | - ), |
|
123 | - 'getpaid-nonce', |
|
124 | - 'getpaid-nonce' |
|
125 | - ) |
|
126 | - ), |
|
127 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
128 | - ); |
|
129 | - |
|
130 | - } |
|
131 | - |
|
132 | - return $actions; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
16 | + * Hook in methods. |
|
17 | + */ |
|
18 | + public static function init() { |
|
19 | + |
|
20 | + // Init metaboxes. |
|
21 | + GetPaid_Metaboxes::init(); |
|
22 | + |
|
23 | + // Filter the post updated messages. |
|
24 | + add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
25 | + |
|
26 | + // Filter post actions. |
|
27 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
29 | + |
|
30 | + // Invoice table columns. |
|
31 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
32 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
33 | + add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
34 | + add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
35 | + |
|
36 | + // Items table columns. |
|
37 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
38 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
39 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
40 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
41 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
42 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
43 | + |
|
44 | + // Payment forms columns. |
|
45 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
46 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
47 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
48 | + |
|
49 | + // Discount table columns. |
|
50 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
51 | + add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
52 | + |
|
53 | + // Deleting posts. |
|
54 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
55 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
56 | + |
|
57 | + add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Post updated messages. |
|
62 | + */ |
|
63 | + public static function post_updated_messages( $messages ) { |
|
64 | + global $post; |
|
65 | + |
|
66 | + $messages['wpi_discount'] = array( |
|
67 | + 0 => '', |
|
68 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
69 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
70 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
71 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
72 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
73 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
74 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
75 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
76 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
77 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
78 | + ); |
|
79 | + |
|
80 | + $messages['wpi_payment_form'] = array( |
|
81 | + 0 => '', |
|
82 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
84 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
85 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
86 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
87 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
88 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
89 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
90 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
91 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
92 | + ); |
|
93 | + |
|
94 | + return $messages; |
|
95 | + |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Post row actions. |
|
100 | + */ |
|
101 | + public static function post_row_actions( $actions, $post ) { |
|
102 | + |
|
103 | + $post = get_post( $post ); |
|
104 | + |
|
105 | + // We do not want to edit the default payment form. |
|
106 | + if ( 'wpi_payment_form' == $post->post_type ) { |
|
107 | + |
|
108 | + if ( $post->ID == wpinv_get_default_payment_form() ) { |
|
109 | + unset( $actions['trash'] ); |
|
110 | + unset( $actions['inline hide-if-no-js'] ); |
|
111 | + } |
|
112 | + |
|
113 | + $actions['duplicate'] = sprintf( |
|
114 | + '<a href="%1$s">%2$s</a>', |
|
115 | + esc_url( |
|
116 | + wp_nonce_url( |
|
117 | + add_query_arg( |
|
118 | + array( |
|
119 | + 'getpaid-admin-action' => 'duplicate_form', |
|
120 | + 'form_id' => $post->ID |
|
121 | + ) |
|
122 | + ), |
|
123 | + 'getpaid-nonce', |
|
124 | + 'getpaid-nonce' |
|
125 | + ) |
|
126 | + ), |
|
127 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
128 | + ); |
|
129 | + |
|
130 | + } |
|
131 | + |
|
132 | + return $actions; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | 136 | * Remove bulk edit option from admin side quote listing |
137 | 137 | * |
138 | 138 | * @since 1.0.0 |
139 | 139 | * @param array $actions post actions |
140 | - * @param WP_Post $post |
|
140 | + * @param WP_Post $post |
|
141 | 141 | * @return array $actions actions without edit option |
142 | 142 | */ |
143 | 143 | public static function filter_invoice_row_actions( $actions, $post ) { |
144 | 144 | |
145 | 145 | if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
146 | 146 | |
147 | - $actions = array(); |
|
148 | - $invoice = new WPInv_Invoice( $post ); |
|
149 | - |
|
150 | - $actions['edit'] = sprintf( |
|
151 | - '<a href="%1$s">%2$s</a>', |
|
152 | - esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
153 | - esc_html( __( 'Edit', 'invoicing' ) ) |
|
154 | - ); |
|
155 | - |
|
156 | - if ( ! $invoice->is_draft() ) { |
|
157 | - |
|
158 | - $actions['view'] = sprintf( |
|
159 | - '<a href="%1$s">%2$s</a>', |
|
160 | - esc_url( $invoice->get_view_url() ), |
|
161 | - sprintf( |
|
162 | - esc_html( __( 'View %s', 'invoicing' ) ), |
|
163 | - getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
164 | - ) |
|
165 | - ); |
|
166 | - |
|
167 | - $actions['send'] = sprintf( |
|
168 | - '<a href="%1$s">%2$s</a>', |
|
169 | - esc_url( |
|
170 | - wp_nonce_url( |
|
171 | - add_query_arg( |
|
172 | - array( |
|
173 | - 'getpaid-admin-action' => 'send_invoice', |
|
174 | - 'invoice_id' => $invoice->get_id() |
|
175 | - ) |
|
176 | - ), |
|
177 | - 'getpaid-nonce', |
|
178 | - 'getpaid-nonce' |
|
179 | - ) |
|
180 | - ), |
|
181 | - esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
182 | - ); |
|
183 | - |
|
184 | - } |
|
185 | - |
|
186 | - $actions['duplicate'] = sprintf( |
|
187 | - '<a href="%1$s">%2$s</a>', |
|
188 | - esc_url( |
|
189 | - wp_nonce_url( |
|
190 | - add_query_arg( |
|
191 | - array( |
|
192 | - 'getpaid-admin-action' => 'duplicate_invoice', |
|
193 | - 'invoice_id' => $post->ID |
|
194 | - ) |
|
195 | - ), |
|
196 | - 'getpaid-nonce', |
|
197 | - 'getpaid-nonce' |
|
198 | - ) |
|
199 | - ), |
|
200 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
201 | - ); |
|
147 | + $actions = array(); |
|
148 | + $invoice = new WPInv_Invoice( $post ); |
|
149 | + |
|
150 | + $actions['edit'] = sprintf( |
|
151 | + '<a href="%1$s">%2$s</a>', |
|
152 | + esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
153 | + esc_html( __( 'Edit', 'invoicing' ) ) |
|
154 | + ); |
|
155 | + |
|
156 | + if ( ! $invoice->is_draft() ) { |
|
157 | + |
|
158 | + $actions['view'] = sprintf( |
|
159 | + '<a href="%1$s">%2$s</a>', |
|
160 | + esc_url( $invoice->get_view_url() ), |
|
161 | + sprintf( |
|
162 | + esc_html( __( 'View %s', 'invoicing' ) ), |
|
163 | + getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
164 | + ) |
|
165 | + ); |
|
166 | + |
|
167 | + $actions['send'] = sprintf( |
|
168 | + '<a href="%1$s">%2$s</a>', |
|
169 | + esc_url( |
|
170 | + wp_nonce_url( |
|
171 | + add_query_arg( |
|
172 | + array( |
|
173 | + 'getpaid-admin-action' => 'send_invoice', |
|
174 | + 'invoice_id' => $invoice->get_id() |
|
175 | + ) |
|
176 | + ), |
|
177 | + 'getpaid-nonce', |
|
178 | + 'getpaid-nonce' |
|
179 | + ) |
|
180 | + ), |
|
181 | + esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
182 | + ); |
|
183 | + |
|
184 | + } |
|
185 | + |
|
186 | + $actions['duplicate'] = sprintf( |
|
187 | + '<a href="%1$s">%2$s</a>', |
|
188 | + esc_url( |
|
189 | + wp_nonce_url( |
|
190 | + add_query_arg( |
|
191 | + array( |
|
192 | + 'getpaid-admin-action' => 'duplicate_invoice', |
|
193 | + 'invoice_id' => $post->ID |
|
194 | + ) |
|
195 | + ), |
|
196 | + 'getpaid-nonce', |
|
197 | + 'getpaid-nonce' |
|
198 | + ) |
|
199 | + ), |
|
200 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
201 | + ); |
|
202 | 202 | |
203 | 203 | } |
204 | 204 | |
205 | 205 | return $actions; |
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Returns an array of invoice table columns. |
|
210 | - */ |
|
211 | - public static function invoice_columns( $columns ) { |
|
212 | - |
|
213 | - $columns = array( |
|
214 | - 'cb' => $columns['cb'], |
|
215 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
216 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
217 | - 'invoice_date' => __( 'Created', 'invoicing' ), |
|
218 | - 'payment_date' => __( 'Completed', 'invoicing' ), |
|
219 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
220 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
221 | - 'status' => __( 'Status', 'invoicing' ), |
|
222 | - ); |
|
223 | - |
|
224 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Displays invoice table columns. |
|
229 | - */ |
|
230 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
231 | - |
|
232 | - $invoice = new WPInv_Invoice( $post_id ); |
|
233 | - |
|
234 | - switch ( $column_name ) { |
|
235 | - |
|
236 | - case 'invoice_date' : |
|
237 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
238 | - $date = getpaid_format_date_value( $date_time, "—", true ); |
|
239 | - echo "<span title='$date_time'>$date</span>"; |
|
240 | - break; |
|
241 | - |
|
242 | - case 'payment_date' : |
|
243 | - |
|
244 | - if ( $invoice->is_paid() ) { |
|
245 | - $date_time = esc_attr( $invoice->get_completed_date() ); |
|
246 | - $date = getpaid_format_date_value( $date_time, "—", true ); |
|
247 | - echo "<span title='$date_time'>$date</span>"; |
|
248 | - } else { |
|
249 | - echo "—"; |
|
250 | - } |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Returns an array of invoice table columns. |
|
210 | + */ |
|
211 | + public static function invoice_columns( $columns ) { |
|
212 | + |
|
213 | + $columns = array( |
|
214 | + 'cb' => $columns['cb'], |
|
215 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
216 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
217 | + 'invoice_date' => __( 'Created', 'invoicing' ), |
|
218 | + 'payment_date' => __( 'Completed', 'invoicing' ), |
|
219 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
220 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
221 | + 'status' => __( 'Status', 'invoicing' ), |
|
222 | + ); |
|
223 | + |
|
224 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Displays invoice table columns. |
|
229 | + */ |
|
230 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
231 | + |
|
232 | + $invoice = new WPInv_Invoice( $post_id ); |
|
233 | + |
|
234 | + switch ( $column_name ) { |
|
235 | + |
|
236 | + case 'invoice_date' : |
|
237 | + $date_time = esc_attr( $invoice->get_created_date() ); |
|
238 | + $date = getpaid_format_date_value( $date_time, "—", true ); |
|
239 | + echo "<span title='$date_time'>$date</span>"; |
|
240 | + break; |
|
241 | + |
|
242 | + case 'payment_date' : |
|
243 | + |
|
244 | + if ( $invoice->is_paid() ) { |
|
245 | + $date_time = esc_attr( $invoice->get_completed_date() ); |
|
246 | + $date = getpaid_format_date_value( $date_time, "—", true ); |
|
247 | + echo "<span title='$date_time'>$date</span>"; |
|
248 | + } else { |
|
249 | + echo "—"; |
|
250 | + } |
|
251 | 251 | |
252 | - break; |
|
252 | + break; |
|
253 | 253 | |
254 | - case 'amount' : |
|
254 | + case 'amount' : |
|
255 | 255 | |
256 | - $amount = $invoice->get_total(); |
|
257 | - $formated_amount = wpinv_price( $amount, $invoice->get_currency() ); |
|
256 | + $amount = $invoice->get_total(); |
|
257 | + $formated_amount = wpinv_price( $amount, $invoice->get_currency() ); |
|
258 | 258 | |
259 | - if ( $invoice->is_refunded() ) { |
|
260 | - $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
261 | - echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
262 | - } else { |
|
259 | + if ( $invoice->is_refunded() ) { |
|
260 | + $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
261 | + echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
262 | + } else { |
|
263 | 263 | |
264 | - $discount = $invoice->get_total_discount(); |
|
264 | + $discount = $invoice->get_total_discount(); |
|
265 | 265 | |
266 | - if ( ! empty( $discount ) ) { |
|
267 | - $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
268 | - echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
269 | - } else { |
|
270 | - echo $formated_amount; |
|
271 | - } |
|
266 | + if ( ! empty( $discount ) ) { |
|
267 | + $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
268 | + echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
269 | + } else { |
|
270 | + echo $formated_amount; |
|
271 | + } |
|
272 | 272 | |
273 | - } |
|
273 | + } |
|
274 | 274 | |
275 | - break; |
|
275 | + break; |
|
276 | 276 | |
277 | - case 'status' : |
|
278 | - $status = esc_html( $invoice->get_status() ); |
|
279 | - $status_label = esc_html( $invoice->get_status_nicename() ); |
|
277 | + case 'status' : |
|
278 | + $status = esc_html( $invoice->get_status() ); |
|
279 | + $status_label = esc_html( $invoice->get_status_nicename() ); |
|
280 | 280 | |
281 | - // If it is paid, show the gateway title. |
|
282 | - if ( $invoice->is_paid() ) { |
|
283 | - $gateway = esc_html( $invoice->get_gateway_title() ); |
|
284 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
281 | + // If it is paid, show the gateway title. |
|
282 | + if ( $invoice->is_paid() ) { |
|
283 | + $gateway = esc_html( $invoice->get_gateway_title() ); |
|
284 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
285 | 285 | |
286 | - echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
287 | - } else { |
|
288 | - echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
289 | - } |
|
286 | + echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
287 | + } else { |
|
288 | + echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
289 | + } |
|
290 | 290 | |
291 | - // If it is not paid, display the overdue and view status. |
|
292 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
291 | + // If it is not paid, display the overdue and view status. |
|
292 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
293 | 293 | |
294 | - // Invoice view status. |
|
295 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
296 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
297 | - } else { |
|
298 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
299 | - } |
|
294 | + // Invoice view status. |
|
295 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
296 | + echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
297 | + } else { |
|
298 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
299 | + } |
|
300 | 300 | |
301 | - // Display the overview status. |
|
302 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
303 | - $due_date = $invoice->get_due_date(); |
|
304 | - $fomatted = getpaid_format_date( $due_date ); |
|
301 | + // Display the overview status. |
|
302 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
303 | + $due_date = $invoice->get_due_date(); |
|
304 | + $fomatted = getpaid_format_date( $due_date ); |
|
305 | 305 | |
306 | - if ( ! empty( $fomatted ) ) { |
|
307 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
308 | - echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
309 | - } |
|
310 | - } |
|
306 | + if ( ! empty( $fomatted ) ) { |
|
307 | + $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
308 | + echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
309 | + } |
|
310 | + } |
|
311 | 311 | |
312 | - } |
|
312 | + } |
|
313 | 313 | |
314 | - break; |
|
314 | + break; |
|
315 | 315 | |
316 | - case 'recurring': |
|
316 | + case 'recurring': |
|
317 | 317 | |
318 | - if ( $invoice->is_recurring() ) { |
|
319 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
320 | - } else { |
|
321 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
322 | - } |
|
323 | - break; |
|
318 | + if ( $invoice->is_recurring() ) { |
|
319 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
320 | + } else { |
|
321 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
322 | + } |
|
323 | + break; |
|
324 | 324 | |
325 | - case 'number' : |
|
325 | + case 'number' : |
|
326 | 326 | |
327 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
328 | - $invoice_number = esc_html( $invoice->get_number() ); |
|
329 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
327 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
328 | + $invoice_number = esc_html( $invoice->get_number() ); |
|
329 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
330 | 330 | |
331 | - echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
331 | + echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
332 | 332 | |
333 | - break; |
|
333 | + break; |
|
334 | 334 | |
335 | - case 'customer' : |
|
335 | + case 'customer' : |
|
336 | 336 | |
337 | - $customer_name = $invoice->get_user_full_name(); |
|
337 | + $customer_name = $invoice->get_user_full_name(); |
|
338 | 338 | |
339 | - if ( empty( $customer_name ) ) { |
|
340 | - $customer_name = $invoice->get_email(); |
|
341 | - } |
|
339 | + if ( empty( $customer_name ) ) { |
|
340 | + $customer_name = $invoice->get_email(); |
|
341 | + } |
|
342 | 342 | |
343 | - if ( ! empty( $customer_name ) ) { |
|
344 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
345 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
346 | - echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
347 | - } else { |
|
348 | - echo '<div>—</div>'; |
|
349 | - } |
|
343 | + if ( ! empty( $customer_name ) ) { |
|
344 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
345 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
346 | + echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
347 | + } else { |
|
348 | + echo '<div>—</div>'; |
|
349 | + } |
|
350 | 350 | |
351 | - break; |
|
351 | + break; |
|
352 | 352 | |
353 | - } |
|
353 | + } |
|
354 | 354 | |
355 | - } |
|
355 | + } |
|
356 | 356 | |
357 | - /** |
|
358 | - * Displays invoice bulk actions. |
|
359 | - */ |
|
360 | - public static function invoice_bulk_actions( $actions ) { |
|
361 | - $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
362 | - return $actions; |
|
363 | - } |
|
357 | + /** |
|
358 | + * Displays invoice bulk actions. |
|
359 | + */ |
|
360 | + public static function invoice_bulk_actions( $actions ) { |
|
361 | + $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
362 | + return $actions; |
|
363 | + } |
|
364 | 364 | |
365 | - /** |
|
366 | - * Processes invoice bulk actions. |
|
367 | - */ |
|
368 | - public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
365 | + /** |
|
366 | + * Processes invoice bulk actions. |
|
367 | + */ |
|
368 | + public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
369 | 369 | |
370 | - if ( $action == 'resend-invoice' ) { |
|
370 | + if ( $action == 'resend-invoice' ) { |
|
371 | 371 | |
372 | - $success = false; |
|
373 | - foreach ( $post_ids as $post_id ) { |
|
374 | - $success = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
375 | - } |
|
372 | + $success = false; |
|
373 | + foreach ( $post_ids as $post_id ) { |
|
374 | + $success = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
375 | + } |
|
376 | 376 | |
377 | - if ( $success ) { |
|
378 | - getpaid_admin()->show_success( __( 'Invoices were successfully sent', 'invoicing' ) ); |
|
379 | - } else { |
|
380 | - getpaid_admin()->show_error( __( 'Could not send some invoices', 'invoicing' ) ); |
|
381 | - } |
|
377 | + if ( $success ) { |
|
378 | + getpaid_admin()->show_success( __( 'Invoices were successfully sent', 'invoicing' ) ); |
|
379 | + } else { |
|
380 | + getpaid_admin()->show_error( __( 'Could not send some invoices', 'invoicing' ) ); |
|
381 | + } |
|
382 | 382 | |
383 | - } |
|
383 | + } |
|
384 | 384 | |
385 | - return $redirect_url; |
|
385 | + return $redirect_url; |
|
386 | 386 | |
387 | - } |
|
387 | + } |
|
388 | 388 | |
389 | - /** |
|
390 | - * Returns an array of payment forms table columns. |
|
391 | - */ |
|
392 | - public static function payment_form_columns( $columns ) { |
|
389 | + /** |
|
390 | + * Returns an array of payment forms table columns. |
|
391 | + */ |
|
392 | + public static function payment_form_columns( $columns ) { |
|
393 | 393 | |
394 | - $columns = array( |
|
395 | - 'cb' => $columns['cb'], |
|
396 | - 'title' => __( 'Name', 'invoicing' ), |
|
397 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
398 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
399 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
400 | - 'items' => __( 'Items', 'invoicing' ), |
|
401 | - 'date' => __( 'Date', 'invoicing' ), |
|
402 | - ); |
|
394 | + $columns = array( |
|
395 | + 'cb' => $columns['cb'], |
|
396 | + 'title' => __( 'Name', 'invoicing' ), |
|
397 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
398 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
399 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
400 | + 'items' => __( 'Items', 'invoicing' ), |
|
401 | + 'date' => __( 'Date', 'invoicing' ), |
|
402 | + ); |
|
403 | 403 | |
404 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
404 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
405 | 405 | |
406 | - } |
|
406 | + } |
|
407 | 407 | |
408 | - /** |
|
409 | - * Displays payment form table columns. |
|
410 | - */ |
|
411 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
408 | + /** |
|
409 | + * Displays payment form table columns. |
|
410 | + */ |
|
411 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
412 | 412 | |
413 | - // Retrieve the payment form. |
|
414 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
413 | + // Retrieve the payment form. |
|
414 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
415 | 415 | |
416 | - switch ( $column_name ) { |
|
416 | + switch ( $column_name ) { |
|
417 | 417 | |
418 | - case 'earnings' : |
|
419 | - echo wpinv_price( $form->get_earned() ); |
|
420 | - break; |
|
418 | + case 'earnings' : |
|
419 | + echo wpinv_price( $form->get_earned() ); |
|
420 | + break; |
|
421 | 421 | |
422 | - case 'refunds' : |
|
423 | - echo wpinv_price( $form->get_refunded() ); |
|
424 | - break; |
|
422 | + case 'refunds' : |
|
423 | + echo wpinv_price( $form->get_refunded() ); |
|
424 | + break; |
|
425 | 425 | |
426 | - case 'refunds' : |
|
427 | - echo wpinv_price( $form->get_refunded() ); |
|
428 | - break; |
|
426 | + case 'refunds' : |
|
427 | + echo wpinv_price( $form->get_refunded() ); |
|
428 | + break; |
|
429 | 429 | |
430 | - case 'shortcode' : |
|
430 | + case 'shortcode' : |
|
431 | 431 | |
432 | - if ( $form->is_default() ) { |
|
433 | - echo '—'; |
|
434 | - } else { |
|
435 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
436 | - } |
|
432 | + if ( $form->is_default() ) { |
|
433 | + echo '—'; |
|
434 | + } else { |
|
435 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
436 | + } |
|
437 | 437 | |
438 | - break; |
|
438 | + break; |
|
439 | 439 | |
440 | - case 'items' : |
|
440 | + case 'items' : |
|
441 | 441 | |
442 | - $items = $form->get_items(); |
|
442 | + $items = $form->get_items(); |
|
443 | 443 | |
444 | - if ( $form->is_default() || empty( $items ) ) { |
|
445 | - echo '—'; |
|
446 | - return; |
|
447 | - } |
|
444 | + if ( $form->is_default() || empty( $items ) ) { |
|
445 | + echo '—'; |
|
446 | + return; |
|
447 | + } |
|
448 | 448 | |
449 | - $_items = array(); |
|
449 | + $_items = array(); |
|
450 | 450 | |
451 | - foreach ( $items as $item ) { |
|
452 | - $url = $item->get_edit_url(); |
|
451 | + foreach ( $items as $item ) { |
|
452 | + $url = $item->get_edit_url(); |
|
453 | 453 | |
454 | - if ( empty( $url ) ) { |
|
455 | - $_items[] = esc_html( $item->get_name() ); |
|
456 | - } else { |
|
457 | - $_items[] = sprintf( |
|
458 | - '<a href="%s">%s</a>', |
|
459 | - esc_url( $url ), |
|
460 | - esc_html( $item->get_name() ) |
|
461 | - ); |
|
462 | - } |
|
454 | + if ( empty( $url ) ) { |
|
455 | + $_items[] = esc_html( $item->get_name() ); |
|
456 | + } else { |
|
457 | + $_items[] = sprintf( |
|
458 | + '<a href="%s">%s</a>', |
|
459 | + esc_url( $url ), |
|
460 | + esc_html( $item->get_name() ) |
|
461 | + ); |
|
462 | + } |
|
463 | 463 | |
464 | - } |
|
464 | + } |
|
465 | 465 | |
466 | - echo implode( '<br>', $_items ); |
|
466 | + echo implode( '<br>', $_items ); |
|
467 | 467 | |
468 | - break; |
|
468 | + break; |
|
469 | 469 | |
470 | - } |
|
470 | + } |
|
471 | 471 | |
472 | - } |
|
472 | + } |
|
473 | 473 | |
474 | - /** |
|
475 | - * Filters post states. |
|
476 | - */ |
|
477 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
474 | + /** |
|
475 | + * Filters post states. |
|
476 | + */ |
|
477 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
478 | 478 | |
479 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
480 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
481 | - } |
|
479 | + if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
480 | + $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
481 | + } |
|
482 | 482 | |
483 | - return $post_states; |
|
484 | - |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * Returns an array of coupon table columns. |
|
489 | - */ |
|
490 | - public static function discount_columns( $columns ) { |
|
491 | - |
|
492 | - $columns = array( |
|
493 | - 'cb' => $columns['cb'], |
|
494 | - 'title' => __( 'Name', 'invoicing' ), |
|
495 | - 'code' => __( 'Code', 'invoicing' ), |
|
496 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
497 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
498 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
499 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
500 | - ); |
|
501 | - |
|
502 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
503 | - } |
|
504 | - |
|
505 | - /** |
|
506 | - * Filters post states. |
|
507 | - */ |
|
508 | - public static function filter_discount_state( $post_states, $post ) { |
|
509 | - |
|
510 | - if ( 'wpi_discount' == $post->post_type ) { |
|
511 | - |
|
512 | - $discount = new WPInv_Discount( $post ); |
|
513 | - |
|
514 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
515 | - |
|
516 | - if ( $status != 'publish' ) { |
|
517 | - return array( |
|
518 | - 'discount_status' => wpinv_discount_status( $status ), |
|
519 | - ); |
|
520 | - } |
|
521 | - |
|
522 | - return array(); |
|
523 | - |
|
524 | - } |
|
525 | - |
|
526 | - return $post_states; |
|
527 | - |
|
528 | - } |
|
529 | - |
|
530 | - /** |
|
531 | - * Returns an array of items table columns. |
|
532 | - */ |
|
533 | - public static function item_columns( $columns ) { |
|
534 | - |
|
535 | - $columns = array( |
|
536 | - 'cb' => $columns['cb'], |
|
537 | - 'title' => __( 'Name', 'invoicing' ), |
|
538 | - 'price' => __( 'Price', 'invoicing' ), |
|
539 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
540 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
541 | - 'type' => __( 'Type', 'invoicing' ), |
|
542 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
543 | - ); |
|
544 | - |
|
545 | - if ( ! wpinv_use_taxes() ) { |
|
546 | - unset( $columns['vat_rule'] ); |
|
547 | - unset( $columns['vat_class'] ); |
|
548 | - } |
|
549 | - |
|
550 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * Returns an array of sortable items table columns. |
|
555 | - */ |
|
556 | - public static function sortable_item_columns( $columns ) { |
|
557 | - |
|
558 | - return array_merge( |
|
559 | - $columns, |
|
560 | - array( |
|
561 | - 'price' => 'price', |
|
562 | - 'vat_rule' => 'vat_rule', |
|
563 | - 'vat_class' => 'vat_class', |
|
564 | - 'type' => 'type', |
|
565 | - ) |
|
566 | - ); |
|
567 | - |
|
568 | - } |
|
569 | - |
|
570 | - /** |
|
571 | - * Displays items table columns. |
|
572 | - */ |
|
573 | - public static function display_item_columns( $column_name, $post_id ) { |
|
483 | + return $post_states; |
|
484 | + |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * Returns an array of coupon table columns. |
|
489 | + */ |
|
490 | + public static function discount_columns( $columns ) { |
|
491 | + |
|
492 | + $columns = array( |
|
493 | + 'cb' => $columns['cb'], |
|
494 | + 'title' => __( 'Name', 'invoicing' ), |
|
495 | + 'code' => __( 'Code', 'invoicing' ), |
|
496 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
497 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
498 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
499 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
500 | + ); |
|
501 | + |
|
502 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
503 | + } |
|
504 | + |
|
505 | + /** |
|
506 | + * Filters post states. |
|
507 | + */ |
|
508 | + public static function filter_discount_state( $post_states, $post ) { |
|
509 | + |
|
510 | + if ( 'wpi_discount' == $post->post_type ) { |
|
511 | + |
|
512 | + $discount = new WPInv_Discount( $post ); |
|
513 | + |
|
514 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
515 | + |
|
516 | + if ( $status != 'publish' ) { |
|
517 | + return array( |
|
518 | + 'discount_status' => wpinv_discount_status( $status ), |
|
519 | + ); |
|
520 | + } |
|
521 | + |
|
522 | + return array(); |
|
523 | + |
|
524 | + } |
|
525 | + |
|
526 | + return $post_states; |
|
527 | + |
|
528 | + } |
|
529 | + |
|
530 | + /** |
|
531 | + * Returns an array of items table columns. |
|
532 | + */ |
|
533 | + public static function item_columns( $columns ) { |
|
534 | + |
|
535 | + $columns = array( |
|
536 | + 'cb' => $columns['cb'], |
|
537 | + 'title' => __( 'Name', 'invoicing' ), |
|
538 | + 'price' => __( 'Price', 'invoicing' ), |
|
539 | + 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
540 | + 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
541 | + 'type' => __( 'Type', 'invoicing' ), |
|
542 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
543 | + ); |
|
544 | + |
|
545 | + if ( ! wpinv_use_taxes() ) { |
|
546 | + unset( $columns['vat_rule'] ); |
|
547 | + unset( $columns['vat_class'] ); |
|
548 | + } |
|
549 | + |
|
550 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Returns an array of sortable items table columns. |
|
555 | + */ |
|
556 | + public static function sortable_item_columns( $columns ) { |
|
557 | + |
|
558 | + return array_merge( |
|
559 | + $columns, |
|
560 | + array( |
|
561 | + 'price' => 'price', |
|
562 | + 'vat_rule' => 'vat_rule', |
|
563 | + 'vat_class' => 'vat_class', |
|
564 | + 'type' => 'type', |
|
565 | + ) |
|
566 | + ); |
|
567 | + |
|
568 | + } |
|
569 | + |
|
570 | + /** |
|
571 | + * Displays items table columns. |
|
572 | + */ |
|
573 | + public static function display_item_columns( $column_name, $post_id ) { |
|
574 | 574 | |
575 | - $item = new WPInv_Item( $post_id ); |
|
575 | + $item = new WPInv_Item( $post_id ); |
|
576 | 576 | |
577 | - switch ( $column_name ) { |
|
577 | + switch ( $column_name ) { |
|
578 | 578 | |
579 | - case 'price' : |
|
579 | + case 'price' : |
|
580 | 580 | |
581 | - if ( ! $item->is_recurring() ) { |
|
582 | - echo $item->get_the_price(); |
|
583 | - break; |
|
584 | - } |
|
581 | + if ( ! $item->is_recurring() ) { |
|
582 | + echo $item->get_the_price(); |
|
583 | + break; |
|
584 | + } |
|
585 | 585 | |
586 | - $price = wp_sprintf( |
|
587 | - __( '%s / %s', 'invoicing' ), |
|
588 | - $item->get_the_price(), |
|
589 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
590 | - ); |
|
586 | + $price = wp_sprintf( |
|
587 | + __( '%s / %s', 'invoicing' ), |
|
588 | + $item->get_the_price(), |
|
589 | + getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
590 | + ); |
|
591 | 591 | |
592 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
593 | - echo $price; |
|
594 | - break; |
|
595 | - } |
|
592 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
593 | + echo $price; |
|
594 | + break; |
|
595 | + } |
|
596 | 596 | |
597 | - echo $item->get_the_initial_price(); |
|
597 | + echo $item->get_the_initial_price(); |
|
598 | 598 | |
599 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
600 | - break; |
|
599 | + echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
600 | + break; |
|
601 | 601 | |
602 | - case 'vat_rule' : |
|
603 | - echo getpaid_get_tax_rule_label( $item->get_vat_rule() ); |
|
604 | - break; |
|
602 | + case 'vat_rule' : |
|
603 | + echo getpaid_get_tax_rule_label( $item->get_vat_rule() ); |
|
604 | + break; |
|
605 | 605 | |
606 | - case 'vat_class' : |
|
607 | - echo getpaid_get_tax_class_label( $item->get_vat_class() ); |
|
608 | - break; |
|
606 | + case 'vat_class' : |
|
607 | + echo getpaid_get_tax_class_label( $item->get_vat_class() ); |
|
608 | + break; |
|
609 | 609 | |
610 | - case 'shortcode' : |
|
611 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
612 | - break; |
|
610 | + case 'shortcode' : |
|
611 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
612 | + break; |
|
613 | 613 | |
614 | - case 'type' : |
|
615 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
616 | - break; |
|
614 | + case 'type' : |
|
615 | + echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
616 | + break; |
|
617 | 617 | |
618 | - } |
|
618 | + } |
|
619 | 619 | |
620 | - } |
|
620 | + } |
|
621 | 621 | |
622 | - /** |
|
623 | - * Lets users filter items using taxes. |
|
624 | - */ |
|
625 | - public static function add_item_filters( $post_type ) { |
|
622 | + /** |
|
623 | + * Lets users filter items using taxes. |
|
624 | + */ |
|
625 | + public static function add_item_filters( $post_type ) { |
|
626 | 626 | |
627 | - // Abort if we're not dealing with items. |
|
628 | - if ( $post_type != 'wpi_item' ) { |
|
629 | - return; |
|
630 | - } |
|
627 | + // Abort if we're not dealing with items. |
|
628 | + if ( $post_type != 'wpi_item' ) { |
|
629 | + return; |
|
630 | + } |
|
631 | 631 | |
632 | - // Filter by vat rules. |
|
633 | - if ( wpinv_use_taxes() ) { |
|
632 | + // Filter by vat rules. |
|
633 | + if ( wpinv_use_taxes() ) { |
|
634 | 634 | |
635 | - // Sanitize selected vat rule. |
|
636 | - $vat_rule = ''; |
|
637 | - $vat_rules = getpaid_get_tax_rules(); |
|
638 | - if ( isset( $_GET['vat_rule'] ) ) { |
|
639 | - $vat_rule = $_GET['vat_rule']; |
|
640 | - } |
|
641 | - |
|
642 | - // Filter by VAT rule. |
|
643 | - echo wpinv_html_select( |
|
644 | - array( |
|
645 | - 'options' => array_merge( |
|
646 | - array( |
|
647 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
648 | - ), |
|
649 | - $vat_rules |
|
650 | - ), |
|
651 | - 'name' => 'vat_rule', |
|
652 | - 'id' => 'vat_rule', |
|
653 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
654 | - 'show_option_all' => false, |
|
655 | - 'show_option_none' => false, |
|
656 | - ) |
|
657 | - ); |
|
658 | - |
|
659 | - // Filter by VAT class. |
|
635 | + // Sanitize selected vat rule. |
|
636 | + $vat_rule = ''; |
|
637 | + $vat_rules = getpaid_get_tax_rules(); |
|
638 | + if ( isset( $_GET['vat_rule'] ) ) { |
|
639 | + $vat_rule = $_GET['vat_rule']; |
|
640 | + } |
|
641 | + |
|
642 | + // Filter by VAT rule. |
|
643 | + echo wpinv_html_select( |
|
644 | + array( |
|
645 | + 'options' => array_merge( |
|
646 | + array( |
|
647 | + '' => __( 'All VAT rules', 'invoicing' ) |
|
648 | + ), |
|
649 | + $vat_rules |
|
650 | + ), |
|
651 | + 'name' => 'vat_rule', |
|
652 | + 'id' => 'vat_rule', |
|
653 | + 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
654 | + 'show_option_all' => false, |
|
655 | + 'show_option_none' => false, |
|
656 | + ) |
|
657 | + ); |
|
658 | + |
|
659 | + // Filter by VAT class. |
|
660 | 660 | |
661 | - // Sanitize selected vat rule. |
|
662 | - $vat_class = ''; |
|
663 | - $vat_classes = getpaid_get_tax_classes(); |
|
664 | - if ( isset( $_GET['vat_class'] ) ) { |
|
665 | - $vat_class = $_GET['vat_class']; |
|
666 | - } |
|
667 | - |
|
668 | - echo wpinv_html_select( |
|
669 | - array( |
|
670 | - 'options' => array_merge( |
|
671 | - array( |
|
672 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
673 | - ), |
|
674 | - $vat_classes |
|
675 | - ), |
|
676 | - 'name' => 'vat_class', |
|
677 | - 'id' => 'vat_class', |
|
678 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
679 | - 'show_option_all' => false, |
|
680 | - 'show_option_none' => false, |
|
681 | - ) |
|
682 | - ); |
|
683 | - |
|
684 | - } |
|
685 | - |
|
686 | - // Filter by item type. |
|
687 | - $type = ''; |
|
688 | - if ( isset( $_GET['type'] ) ) { |
|
689 | - $type = $_GET['type']; |
|
690 | - } |
|
691 | - |
|
692 | - echo wpinv_html_select( |
|
693 | - array( |
|
694 | - 'options' => array_merge( |
|
695 | - array( |
|
696 | - '' => __( 'All item types', 'invoicing' ) |
|
697 | - ), |
|
698 | - wpinv_get_item_types() |
|
699 | - ), |
|
700 | - 'name' => 'type', |
|
701 | - 'id' => 'type', |
|
702 | - 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
703 | - 'show_option_all' => false, |
|
704 | - 'show_option_none' => false, |
|
705 | - ) |
|
706 | - ); |
|
707 | - |
|
708 | - } |
|
709 | - |
|
710 | - /** |
|
711 | - * Filters the item query. |
|
712 | - */ |
|
713 | - public static function filter_item_query( $query ) { |
|
714 | - |
|
715 | - // modify the query only if it admin and main query. |
|
716 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
717 | - return $query; |
|
718 | - } |
|
719 | - |
|
720 | - // we want to modify the query for our items. |
|
721 | - if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){ |
|
722 | - return $query; |
|
723 | - } |
|
724 | - |
|
725 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
726 | - $query->query_vars['meta_query'] = array(); |
|
727 | - } |
|
728 | - |
|
729 | - // Filter vat rule type |
|
661 | + // Sanitize selected vat rule. |
|
662 | + $vat_class = ''; |
|
663 | + $vat_classes = getpaid_get_tax_classes(); |
|
664 | + if ( isset( $_GET['vat_class'] ) ) { |
|
665 | + $vat_class = $_GET['vat_class']; |
|
666 | + } |
|
667 | + |
|
668 | + echo wpinv_html_select( |
|
669 | + array( |
|
670 | + 'options' => array_merge( |
|
671 | + array( |
|
672 | + '' => __( 'All VAT classes', 'invoicing' ) |
|
673 | + ), |
|
674 | + $vat_classes |
|
675 | + ), |
|
676 | + 'name' => 'vat_class', |
|
677 | + 'id' => 'vat_class', |
|
678 | + 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
679 | + 'show_option_all' => false, |
|
680 | + 'show_option_none' => false, |
|
681 | + ) |
|
682 | + ); |
|
683 | + |
|
684 | + } |
|
685 | + |
|
686 | + // Filter by item type. |
|
687 | + $type = ''; |
|
688 | + if ( isset( $_GET['type'] ) ) { |
|
689 | + $type = $_GET['type']; |
|
690 | + } |
|
691 | + |
|
692 | + echo wpinv_html_select( |
|
693 | + array( |
|
694 | + 'options' => array_merge( |
|
695 | + array( |
|
696 | + '' => __( 'All item types', 'invoicing' ) |
|
697 | + ), |
|
698 | + wpinv_get_item_types() |
|
699 | + ), |
|
700 | + 'name' => 'type', |
|
701 | + 'id' => 'type', |
|
702 | + 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
703 | + 'show_option_all' => false, |
|
704 | + 'show_option_none' => false, |
|
705 | + ) |
|
706 | + ); |
|
707 | + |
|
708 | + } |
|
709 | + |
|
710 | + /** |
|
711 | + * Filters the item query. |
|
712 | + */ |
|
713 | + public static function filter_item_query( $query ) { |
|
714 | + |
|
715 | + // modify the query only if it admin and main query. |
|
716 | + if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
717 | + return $query; |
|
718 | + } |
|
719 | + |
|
720 | + // we want to modify the query for our items. |
|
721 | + if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){ |
|
722 | + return $query; |
|
723 | + } |
|
724 | + |
|
725 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
726 | + $query->query_vars['meta_query'] = array(); |
|
727 | + } |
|
728 | + |
|
729 | + // Filter vat rule type |
|
730 | 730 | if ( ! empty( $_GET['vat_rule'] ) ) { |
731 | 731 | $query->query_vars['meta_query'][] = array( |
732 | 732 | 'key' => '_wpinv_vat_rule', |
@@ -751,97 +751,97 @@ discard block |
||
751 | 751 | 'value' => sanitize_text_field( $_GET['type'] ), |
752 | 752 | 'compare' => '=' |
753 | 753 | ); |
754 | - } |
|
755 | - |
|
756 | - } |
|
757 | - |
|
758 | - /** |
|
759 | - * Reorders items. |
|
760 | - */ |
|
761 | - public static function reorder_items( $vars ) { |
|
762 | - global $typenow; |
|
763 | - |
|
764 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
765 | - return $vars; |
|
766 | - } |
|
767 | - |
|
768 | - // By item type. |
|
769 | - if ( 'type' == $vars['orderby'] ) { |
|
770 | - return array_merge( |
|
771 | - $vars, |
|
772 | - array( |
|
773 | - 'meta_key' => '_wpinv_type', |
|
774 | - 'orderby' => 'meta_value' |
|
775 | - ) |
|
776 | - ); |
|
777 | - } |
|
778 | - |
|
779 | - // By vat class. |
|
780 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
781 | - return array_merge( |
|
782 | - $vars, |
|
783 | - array( |
|
784 | - 'meta_key' => '_wpinv_vat_class', |
|
785 | - 'orderby' => 'meta_value' |
|
786 | - ) |
|
787 | - ); |
|
788 | - } |
|
789 | - |
|
790 | - // By vat rule. |
|
791 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
792 | - return array_merge( |
|
793 | - $vars, |
|
794 | - array( |
|
795 | - 'meta_key' => '_wpinv_vat_rule', |
|
796 | - 'orderby' => 'meta_value' |
|
797 | - ) |
|
798 | - ); |
|
799 | - } |
|
800 | - |
|
801 | - // By price. |
|
802 | - if ( 'price' == $vars['orderby'] ) { |
|
803 | - return array_merge( |
|
804 | - $vars, |
|
805 | - array( |
|
806 | - 'meta_key' => '_wpinv_price', |
|
807 | - 'orderby' => 'meta_value_num' |
|
808 | - ) |
|
809 | - ); |
|
810 | - } |
|
811 | - |
|
812 | - return $vars; |
|
813 | - |
|
814 | - } |
|
815 | - |
|
816 | - /** |
|
817 | - * Fired when deleting a post. |
|
818 | - */ |
|
819 | - public static function delete_post( $post_id ) { |
|
820 | - |
|
821 | - switch ( get_post_type( $post_id ) ) { |
|
822 | - |
|
823 | - case 'wpi_item' : |
|
824 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
825 | - break; |
|
826 | - |
|
827 | - case 'wpi_payment_form' : |
|
828 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
829 | - break; |
|
830 | - |
|
831 | - case 'wpi_discount' : |
|
832 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
833 | - break; |
|
834 | - |
|
835 | - case 'wpi_invoice' : |
|
836 | - $invoice = new WPInv_Invoice( $post_id ); |
|
837 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
838 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
839 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
840 | - break; |
|
841 | - } |
|
842 | - } |
|
843 | - |
|
844 | - /** |
|
754 | + } |
|
755 | + |
|
756 | + } |
|
757 | + |
|
758 | + /** |
|
759 | + * Reorders items. |
|
760 | + */ |
|
761 | + public static function reorder_items( $vars ) { |
|
762 | + global $typenow; |
|
763 | + |
|
764 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
765 | + return $vars; |
|
766 | + } |
|
767 | + |
|
768 | + // By item type. |
|
769 | + if ( 'type' == $vars['orderby'] ) { |
|
770 | + return array_merge( |
|
771 | + $vars, |
|
772 | + array( |
|
773 | + 'meta_key' => '_wpinv_type', |
|
774 | + 'orderby' => 'meta_value' |
|
775 | + ) |
|
776 | + ); |
|
777 | + } |
|
778 | + |
|
779 | + // By vat class. |
|
780 | + if ( 'vat_class' == $vars['orderby'] ) { |
|
781 | + return array_merge( |
|
782 | + $vars, |
|
783 | + array( |
|
784 | + 'meta_key' => '_wpinv_vat_class', |
|
785 | + 'orderby' => 'meta_value' |
|
786 | + ) |
|
787 | + ); |
|
788 | + } |
|
789 | + |
|
790 | + // By vat rule. |
|
791 | + if ( 'vat_rule' == $vars['orderby'] ) { |
|
792 | + return array_merge( |
|
793 | + $vars, |
|
794 | + array( |
|
795 | + 'meta_key' => '_wpinv_vat_rule', |
|
796 | + 'orderby' => 'meta_value' |
|
797 | + ) |
|
798 | + ); |
|
799 | + } |
|
800 | + |
|
801 | + // By price. |
|
802 | + if ( 'price' == $vars['orderby'] ) { |
|
803 | + return array_merge( |
|
804 | + $vars, |
|
805 | + array( |
|
806 | + 'meta_key' => '_wpinv_price', |
|
807 | + 'orderby' => 'meta_value_num' |
|
808 | + ) |
|
809 | + ); |
|
810 | + } |
|
811 | + |
|
812 | + return $vars; |
|
813 | + |
|
814 | + } |
|
815 | + |
|
816 | + /** |
|
817 | + * Fired when deleting a post. |
|
818 | + */ |
|
819 | + public static function delete_post( $post_id ) { |
|
820 | + |
|
821 | + switch ( get_post_type( $post_id ) ) { |
|
822 | + |
|
823 | + case 'wpi_item' : |
|
824 | + do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
825 | + break; |
|
826 | + |
|
827 | + case 'wpi_payment_form' : |
|
828 | + do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
829 | + break; |
|
830 | + |
|
831 | + case 'wpi_discount' : |
|
832 | + do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
833 | + break; |
|
834 | + |
|
835 | + case 'wpi_invoice' : |
|
836 | + $invoice = new WPInv_Invoice( $post_id ); |
|
837 | + do_action( "getpaid_before_delete_invoice", $invoice ); |
|
838 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
839 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
840 | + break; |
|
841 | + } |
|
842 | + } |
|
843 | + |
|
844 | + /** |
|
845 | 845 | * Add a post display state for special GetPaid pages in the page list table. |
846 | 846 | * |
847 | 847 | * @param array $post_states An array of post display states. |
@@ -855,22 +855,22 @@ discard block |
||
855 | 855 | $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' ); |
856 | 856 | } |
857 | 857 | |
858 | - foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
858 | + foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
859 | 859 | |
860 | - if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
861 | - $post_states["getpaid_{$post_type}_history_page"] = sprintf( |
|
862 | - __( 'GetPaid %s History Page', 'invoicing' ), |
|
863 | - $label |
|
864 | - ); |
|
865 | - } |
|
860 | + if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
861 | + $post_states["getpaid_{$post_type}_history_page"] = sprintf( |
|
862 | + __( 'GetPaid %s History Page', 'invoicing' ), |
|
863 | + $label |
|
864 | + ); |
|
865 | + } |
|
866 | 866 | |
867 | - } |
|
867 | + } |
|
868 | 868 | |
869 | - if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
869 | + if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
870 | 870 | $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' ); |
871 | 871 | } |
872 | 872 | |
873 | - if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
873 | + if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
874 | 874 | $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' ); |
875 | 875 | } |
876 | 876 |