@@ -1,18 +1,18 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
6 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
7 | 7 | |
8 | -if ( ! empty( $message_body ) ) { |
|
9 | - echo wpautop( wptexturize( $message_body ) ); |
|
8 | +if (!empty($message_body)) { |
|
9 | + echo wpautop(wptexturize($message_body)); |
|
10 | 10 | } |
11 | 11 | |
12 | -do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin ); |
|
12 | +do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin); |
|
13 | 13 | |
14 | -do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin ); |
|
14 | +do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin); |
|
15 | 15 | |
16 | -do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin ); |
|
16 | +do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin); |
|
17 | 17 | |
18 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
19 | 18 | \ No newline at end of file |
19 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
20 | 20 | \ No newline at end of file |
@@ -1,22 +1,22 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
6 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
7 | 7 | |
8 | -do_action( 'wpinv_email_before_note_details', $invoice, $email_type, $sent_to_admin, $customer_note ); |
|
8 | +do_action('wpinv_email_before_note_details', $invoice, $email_type, $sent_to_admin, $customer_note); |
|
9 | 9 | |
10 | -if ( ! empty( $message_body ) ) { |
|
11 | - echo wpautop( wptexturize( $message_body ) ); |
|
10 | +if (!empty($message_body)) { |
|
11 | + echo wpautop(wptexturize($message_body)); |
|
12 | 12 | } |
13 | 13 | |
14 | -do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin ); |
|
14 | +do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin); |
|
15 | 15 | |
16 | -do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin ); |
|
16 | +do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin); |
|
17 | 17 | |
18 | -do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin ); |
|
18 | +do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin); |
|
19 | 19 | |
20 | -do_action( 'wpinv_email_after_note_details', $invoice, $email_type, $sent_to_admin, $customer_note ); |
|
20 | +do_action('wpinv_email_after_note_details', $invoice, $email_type, $sent_to_admin, $customer_note); |
|
21 | 21 | |
22 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
23 | 22 | \ No newline at end of file |
23 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
24 | 24 | \ No newline at end of file |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
6 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
7 | 7 | |
8 | -if ( ! empty( $message_body ) ) { |
|
9 | - echo wpautop( wptexturize( $message_body ) ); |
|
8 | +if (!empty($message_body)) { |
|
9 | + echo wpautop(wptexturize($message_body)); |
|
10 | 10 | } |
11 | 11 | |
12 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
13 | 12 | \ No newline at end of file |
13 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
14 | 14 | \ No newline at end of file |
@@ -29,16 +29,16 @@ |
||
29 | 29 | <table class="table table-bordered table-hover table-responsive wpi-user-subscriptions"> |
30 | 30 | <thead> |
31 | 31 | <tr> |
32 | - <th class="sub-no"><span class="nobr"><?php _e( 'No.', 'invoicing' ); ?></span></th> |
|
33 | - <th class="sub-amount"><span class="nobr"><?php _e( 'Initial Amount', 'invoicing' ); ?></span></th> |
|
34 | - <th class="sub-cycle"><span class="nobr"><?php _e( 'Billing Cycle', 'invoicing' ); ?></span></th> |
|
35 | - <th class="sub-billed"><span class="nobr"><?php _e( 'Times Billed', 'invoicing' ); ?></span></th> |
|
36 | - <th class="sub-status"><span class="nobr"><?php _e( 'Status', 'invoicing' ); ?></span></th> |
|
37 | - <th class="sub-invoice"><span class="nobr"><?php _e( 'Invoice', 'invoicing' ); ?></span></th> |
|
38 | - <th class="sub-item"><span class="nobr"><?php _e( 'Item', 'invoicing' ); ?></span></th> |
|
39 | - <th class="sub-gateway"><span class="nobr"><?php _e( 'Gateway', 'invoicing' ); ?></span></th> |
|
40 | - <th class="sub-expiry"><span class="nobr"><?php _e( 'Expires On', 'invoicing' ); ?></span></th> |
|
41 | - <th class="sub-actions"><span class="nobr"><?php _e( 'Actions', 'invoicing' ); ?></span></th> |
|
32 | + <th class="sub-no"><span class="nobr"><?php _e('No.', 'invoicing'); ?></span></th> |
|
33 | + <th class="sub-amount"><span class="nobr"><?php _e('Initial Amount', 'invoicing'); ?></span></th> |
|
34 | + <th class="sub-cycle"><span class="nobr"><?php _e('Billing Cycle', 'invoicing'); ?></span></th> |
|
35 | + <th class="sub-billed"><span class="nobr"><?php _e('Times Billed', 'invoicing'); ?></span></th> |
|
36 | + <th class="sub-status"><span class="nobr"><?php _e('Status', 'invoicing'); ?></span></th> |
|
37 | + <th class="sub-invoice"><span class="nobr"><?php _e('Invoice', 'invoicing'); ?></span></th> |
|
38 | + <th class="sub-item"><span class="nobr"><?php _e('Item', 'invoicing'); ?></span></th> |
|
39 | + <th class="sub-gateway"><span class="nobr"><?php _e('Gateway', 'invoicing'); ?></span></th> |
|
40 | + <th class="sub-expiry"><span class="nobr"><?php _e('Expires On', 'invoicing'); ?></span></th> |
|
41 | + <th class="sub-actions"><span class="nobr"><?php _e('Actions', 'invoicing'); ?></span></th> |
|
42 | 42 | </tr> |
43 | 43 | </thead> |
44 | 44 |
@@ -1,83 +1,83 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | -if ( !( $user_id = get_current_user_id() ) ) { |
|
6 | +if (!($user_id = get_current_user_id())) { |
|
7 | 7 | ?> |
8 | - <div class="wpinv-empty alert alert-error"><?php _e( 'You are not allowed to access this section', 'invoicing' ) ;?></div> |
|
8 | + <div class="wpinv-empty alert alert-error"><?php _e('You are not allowed to access this section', 'invoicing'); ?></div> |
|
9 | 9 | <?php |
10 | 10 | return; |
11 | 11 | } |
12 | 12 | |
13 | 13 | global $current_page; |
14 | -$current_page = empty( $current_page ) ? 1 : absint( $current_page ); |
|
15 | -$query = apply_filters( 'wpinv_user_invoices_query', array( 'user' => $user_id, 'page' => $current_page, 'paginate' => true ) ); |
|
16 | -$user_invoices = wpinv_get_invoices( $query ); |
|
14 | +$current_page = empty($current_page) ? 1 : absint($current_page); |
|
15 | +$query = apply_filters('wpinv_user_invoices_query', array('user' => $user_id, 'page' => $current_page, 'paginate' => true)); |
|
16 | +$user_invoices = wpinv_get_invoices($query); |
|
17 | 17 | $has_invoices = 0 < $user_invoices->total; |
18 | 18 | |
19 | -do_action( 'wpinv_before_user_invoices', $has_invoices ); ?> |
|
19 | +do_action('wpinv_before_user_invoices', $has_invoices); ?> |
|
20 | 20 | |
21 | -<?php if ( $has_invoices ) { ?> |
|
21 | +<?php if ($has_invoices) { ?> |
|
22 | 22 | <table class="table table-bordered table-hover table-responsive wpi-user-invoices"> |
23 | 23 | <thead> |
24 | 24 | <tr> |
25 | - <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?> |
|
26 | - <th class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>"><span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span></th> |
|
25 | + <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?> |
|
26 | + <th class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>"><span class="nobr"><?php echo esc_html($column_name['title']); ?></span></th> |
|
27 | 27 | <?php endforeach; ?> |
28 | 28 | </tr> |
29 | 29 | </thead> |
30 | 30 | |
31 | 31 | <tbody> |
32 | - <?php foreach ( $user_invoices->invoices as $invoice ) { |
|
32 | + <?php foreach ($user_invoices->invoices as $invoice) { |
|
33 | 33 | ?> |
34 | 34 | <tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>"> |
35 | - <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?> |
|
36 | - <td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>"> |
|
37 | - <?php if ( has_action( 'wpinv_user_invoices_column_' . $column_id ) ) : ?> |
|
38 | - <?php do_action( 'wpinv_user_invoices_column_' . $column_id, $invoice ); ?> |
|
39 | - |
|
40 | - <?php elseif ( 'invoice-number' === $column_id ) : ?> |
|
41 | - <a href="<?php echo esc_url( $invoice->get_view_url() ); ?>"> |
|
42 | - <?php echo _x( '#', 'hash before invoice number', 'invoicing' ) . $invoice->get_number(); ?> |
|
35 | + <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?> |
|
36 | + <td class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>" data-title="<?php echo esc_attr($column_name['title']); ?>"> |
|
37 | + <?php if (has_action('wpinv_user_invoices_column_' . $column_id)) : ?> |
|
38 | + <?php do_action('wpinv_user_invoices_column_' . $column_id, $invoice); ?> |
|
39 | + |
|
40 | + <?php elseif ('invoice-number' === $column_id) : ?> |
|
41 | + <a href="<?php echo esc_url($invoice->get_view_url()); ?>"> |
|
42 | + <?php echo _x('#', 'hash before invoice number', 'invoicing') . $invoice->get_number(); ?> |
|
43 | 43 | </a> |
44 | 44 | |
45 | - <?php elseif ( 'created-date' === $column_id ) : $date = wpinv_get_date_created( $invoice->ID ); $dateYMD = wpinv_get_date_created( $invoice->ID, 'Y-m-d H:i:s' ); ?> |
|
46 | - <time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time> |
|
45 | + <?php elseif ('created-date' === $column_id) : $date = wpinv_get_date_created($invoice->ID); $dateYMD = wpinv_get_date_created($invoice->ID, 'Y-m-d H:i:s'); ?> |
|
46 | + <time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time> |
|
47 | 47 | |
48 | - <?php elseif ( 'payment-date' === $column_id ) : $date = wpinv_get_invoice_date( $invoice->ID, '', false ); $dateYMD = wpinv_get_invoice_date( $invoice->ID, 'Y-m-d H:i:s', false ); ?> |
|
49 | - <time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time> |
|
48 | + <?php elseif ('payment-date' === $column_id) : $date = wpinv_get_invoice_date($invoice->ID, '', false); $dateYMD = wpinv_get_invoice_date($invoice->ID, 'Y-m-d H:i:s', false); ?> |
|
49 | + <time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time> |
|
50 | 50 | |
51 | - <?php elseif ( 'invoice-status' === $column_id ) : ?> |
|
52 | - <?php echo wpinv_invoice_status_label( $invoice_status, $invoice->get_status( true ) ) ; ?> |
|
51 | + <?php elseif ('invoice-status' === $column_id) : ?> |
|
52 | + <?php echo wpinv_invoice_status_label($invoice_status, $invoice->get_status(true)); ?> |
|
53 | 53 | |
54 | - <?php elseif ( 'invoice-total' === $column_id ) : ?> |
|
55 | - <?php echo $invoice->get_total( true ); ?> |
|
54 | + <?php elseif ('invoice-total' === $column_id) : ?> |
|
55 | + <?php echo $invoice->get_total(true); ?> |
|
56 | 56 | |
57 | - <?php elseif ( 'invoice-actions' === $column_id ) : ?> |
|
57 | + <?php elseif ('invoice-actions' === $column_id) : ?> |
|
58 | 58 | <?php |
59 | 59 | $actions = array( |
60 | 60 | 'pay' => array( |
61 | 61 | 'url' => $invoice->get_checkout_payment_url(), |
62 | - 'name' => __( 'Pay Now', 'invoicing' ), |
|
62 | + 'name' => __('Pay Now', 'invoicing'), |
|
63 | 63 | 'class' => 'btn-success' |
64 | 64 | ), |
65 | 65 | 'print' => array( |
66 | 66 | 'url' => $invoice->get_view_url(), |
67 | - 'name' => __( 'Print', 'invoicing' ), |
|
67 | + 'name' => __('Print', 'invoicing'), |
|
68 | 68 | 'class' => 'btn-primary', |
69 | 69 | 'attrs' => 'target="_blank"' |
70 | 70 | ) |
71 | 71 | ); |
72 | 72 | |
73 | - if ( ! $invoice->needs_payment() ) { |
|
74 | - unset( $actions['pay'] ); |
|
73 | + if (!$invoice->needs_payment()) { |
|
74 | + unset($actions['pay']); |
|
75 | 75 | } |
76 | 76 | |
77 | - if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) { |
|
78 | - foreach ( $actions as $key => $action ) { |
|
77 | + if ($actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice)) { |
|
78 | + foreach ($actions as $key => $action) { |
|
79 | 79 | $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
80 | - echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>'; |
|
80 | + echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>'; |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | ?> |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | </tbody> |
90 | 90 | </table> |
91 | 91 | |
92 | - <?php do_action( 'wpinv_before_user_invoices_pagination' ); ?> |
|
92 | + <?php do_action('wpinv_before_user_invoices_pagination'); ?> |
|
93 | 93 | |
94 | - <?php if ( 1 < $user_invoices->max_num_pages ) : ?> |
|
94 | + <?php if (1 < $user_invoices->max_num_pages) : ?> |
|
95 | 95 | <div class="invoicing-Pagination"> |
96 | 96 | <?php |
97 | 97 | $big = 999999; |
@@ -103,20 +103,20 @@ discard block |
||
103 | 103 | else |
104 | 104 | $current_page = 1; |
105 | 105 | |
106 | - echo paginate_links( array( |
|
107 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
106 | + echo paginate_links(array( |
|
107 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
108 | 108 | 'format' => '?paged=%#%', |
109 | - 'current' => max( 1, $current_page ), |
|
109 | + 'current' => max(1, $current_page), |
|
110 | 110 | 'total' => $user_invoices->max_num_pages, |
111 | - ) ); |
|
111 | + )); |
|
112 | 112 | ?> |
113 | 113 | </div> |
114 | 114 | <?php endif; ?> |
115 | 115 | |
116 | 116 | <?php } else { ?> |
117 | 117 | <div class="wpinv-empty alert-info"> |
118 | - <?php _e( 'No invoice has been made yet.', 'invoicing' ); ?> |
|
118 | + <?php _e('No invoice has been made yet.', 'invoicing'); ?> |
|
119 | 119 | </div> |
120 | 120 | <?php } ?> |
121 | 121 | |
122 | -<?php do_action( 'wpinv_after_user_invoices', $has_invoices ); ?> |
|
122 | +<?php do_action('wpinv_after_user_invoices', $has_invoices); ?> |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | * Hook in methods. |
15 | 15 | */ |
16 | 16 | public static function init() { |
17 | - add_action( 'init', array( __CLASS__, 'init_hooks' ), 0 ); |
|
18 | - add_action( 'admin_notices', array( __CLASS__, 'notices' ) ); |
|
17 | + add_action('init', array(__CLASS__, 'init_hooks'), 0); |
|
18 | + add_action('admin_notices', array(__CLASS__, 'notices')); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function init_hooks() { |
22 | - if ( false === ( $page_uris = get_transient( 'wpinv_cache_excluded_uris' ) ) ) { |
|
23 | - $checkout_page = wpinv_get_option( 'checkout_page', '' ); |
|
24 | - $success_page = wpinv_get_option( 'success_page', '' ); |
|
25 | - $failure_page = wpinv_get_option( 'failure_page', '' ); |
|
26 | - $history_page = wpinv_get_option( 'invoice_history_page', '' ); |
|
27 | - $subscr_page = wpinv_get_option( 'invoice_subscription_page', '' ); |
|
28 | - if ( empty( $checkout_page ) || empty( $success_page ) || empty( $failure_page ) || empty( $history_page ) || empty( $subscr_page ) ) { |
|
22 | + if (false === ($page_uris = get_transient('wpinv_cache_excluded_uris'))) { |
|
23 | + $checkout_page = wpinv_get_option('checkout_page', ''); |
|
24 | + $success_page = wpinv_get_option('success_page', ''); |
|
25 | + $failure_page = wpinv_get_option('failure_page', ''); |
|
26 | + $history_page = wpinv_get_option('invoice_history_page', ''); |
|
27 | + $subscr_page = wpinv_get_option('invoice_subscription_page', ''); |
|
28 | + if (empty($checkout_page) || empty($success_page) || empty($failure_page) || empty($history_page) || empty($subscr_page)) { |
|
29 | 29 | return; |
30 | 30 | } |
31 | 31 | |
@@ -39,34 +39,34 @@ discard block |
||
39 | 39 | $page_uris[] = 'p=' . $subscr_page; |
40 | 40 | |
41 | 41 | // Exclude permalinks |
42 | - $checkout_page = get_post( $checkout_page ); |
|
43 | - $success_page = get_post( $success_page ); |
|
44 | - $failure_page = get_post( $failure_page ); |
|
45 | - $history_page = get_post( $history_page ); |
|
46 | - $subscr_page = get_post( $subscr_page ); |
|
42 | + $checkout_page = get_post($checkout_page); |
|
43 | + $success_page = get_post($success_page); |
|
44 | + $failure_page = get_post($failure_page); |
|
45 | + $history_page = get_post($history_page); |
|
46 | + $subscr_page = get_post($subscr_page); |
|
47 | 47 | |
48 | - if ( ! is_null( $checkout_page ) ) { |
|
48 | + if (!is_null($checkout_page)) { |
|
49 | 49 | $page_uris[] = '/' . $checkout_page->post_name; |
50 | 50 | } |
51 | - if ( ! is_null( $success_page ) ) { |
|
51 | + if (!is_null($success_page)) { |
|
52 | 52 | $page_uris[] = '/' . $success_page->post_name; |
53 | 53 | } |
54 | - if ( ! is_null( $failure_page ) ) { |
|
54 | + if (!is_null($failure_page)) { |
|
55 | 55 | $page_uris[] = '/' . $failure_page->post_name; |
56 | 56 | } |
57 | - if ( ! is_null( $history_page ) ) { |
|
57 | + if (!is_null($history_page)) { |
|
58 | 58 | $page_uris[] = '/' . $history_page->post_name; |
59 | 59 | } |
60 | - if ( ! is_null( $subscr_page ) ) { |
|
60 | + if (!is_null($subscr_page)) { |
|
61 | 61 | $page_uris[] = '/' . $subscr_page->post_name; |
62 | 62 | } |
63 | 63 | |
64 | - set_transient( 'wpinv_cache_excluded_uris', $page_uris ); |
|
64 | + set_transient('wpinv_cache_excluded_uris', $page_uris); |
|
65 | 65 | } |
66 | 66 | |
67 | - if ( is_array( $page_uris ) ) { |
|
68 | - foreach( $page_uris as $uri ) { |
|
69 | - if ( strstr( $_SERVER['REQUEST_URI'], $uri ) ) { |
|
67 | + if (is_array($page_uris)) { |
|
68 | + foreach ($page_uris as $uri) { |
|
69 | + if (strstr($_SERVER['REQUEST_URI'], $uri)) { |
|
70 | 70 | self::nocache(); |
71 | 71 | break; |
72 | 72 | } |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | * @access private |
80 | 80 | */ |
81 | 81 | private static function nocache() { |
82 | - if ( ! defined( 'DONOTCACHEPAGE' ) ) { |
|
83 | - define( "DONOTCACHEPAGE", true ); |
|
82 | + if (!defined('DONOTCACHEPAGE')) { |
|
83 | + define("DONOTCACHEPAGE", true); |
|
84 | 84 | } |
85 | - if ( ! defined( 'DONOTCACHEOBJECT' ) ) { |
|
86 | - define( "DONOTCACHEOBJECT", true ); |
|
85 | + if (!defined('DONOTCACHEOBJECT')) { |
|
86 | + define("DONOTCACHEOBJECT", true); |
|
87 | 87 | } |
88 | - if ( ! defined( 'DONOTCACHEDB' ) ) { |
|
89 | - define( "DONOTCACHEDB", true ); |
|
88 | + if (!defined('DONOTCACHEDB')) { |
|
89 | + define("DONOTCACHEDB", true); |
|
90 | 90 | } |
91 | 91 | nocache_headers(); |
92 | 92 | } |
@@ -95,18 +95,18 @@ discard block |
||
95 | 95 | * notices function. |
96 | 96 | */ |
97 | 97 | public static function notices() { |
98 | - if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) { |
|
98 | + if (!function_exists('w3tc_pgcache_flush') || !function_exists('w3_instance')) { |
|
99 | 99 | return; |
100 | 100 | } |
101 | 101 | |
102 | - $config = w3_instance( 'W3_Config' ); |
|
103 | - $enabled = $config->get_integer( 'dbcache.enabled' ); |
|
104 | - $settings = array_map( 'trim', $config->get_array( 'dbcache.reject.sql' ) ); |
|
102 | + $config = w3_instance('W3_Config'); |
|
103 | + $enabled = $config->get_integer('dbcache.enabled'); |
|
104 | + $settings = array_map('trim', $config->get_array('dbcache.reject.sql')); |
|
105 | 105 | |
106 | - if ( $enabled && ! in_array( '_wp_session_', $settings ) ) { |
|
106 | + if ($enabled && !in_array('_wp_session_', $settings)) { |
|
107 | 107 | ?> |
108 | 108 | <div class="error"> |
109 | - <p><?php printf( __( 'In order for <strong>database caching</strong> to work with Invoicing you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'invoicing' ), '<code>_wp_session_</code>', admin_url( 'admin.php?page=w3tc_dbcache' ) ); ?></p> |
|
109 | + <p><?php printf(__('In order for <strong>database caching</strong> to work with Invoicing you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'invoicing'), '<code>_wp_session_</code>', admin_url('admin.php?page=w3tc_dbcache')); ?></p> |
|
110 | 110 | </div> |
111 | 111 | <?php |
112 | 112 | } |
@@ -7,90 +7,90 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_get_discount_types() { |
15 | 15 | $discount_types = array( |
16 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
17 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
16 | + 'percent' => __('Percentage', 'invoicing'), |
|
17 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
18 | 18 | ); |
19 | - return (array)apply_filters( 'wpinv_discount_types', $discount_types ); |
|
19 | + return (array)apply_filters('wpinv_discount_types', $discount_types); |
|
20 | 20 | } |
21 | 21 | |
22 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
22 | +function wpinv_get_discount_type_name($type = '') { |
|
23 | 23 | $types = wpinv_get_discount_types(); |
24 | - return isset( $types[ $type ] ) ? $types[ $type ] : ''; |
|
24 | + return isset($types[$type]) ? $types[$type] : ''; |
|
25 | 25 | } |
26 | 26 | |
27 | -function wpinv_delete_discount( $data ) { |
|
28 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
29 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
27 | +function wpinv_delete_discount($data) { |
|
28 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
29 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
30 | 30 | } |
31 | 31 | |
32 | - if( ! current_user_can( 'manage_options' ) ) { |
|
33 | - wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
32 | + if (!current_user_can('manage_options')) { |
|
33 | + wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | $discount_id = $data['discount']; |
37 | - wpinv_remove_discount( $discount_id ); |
|
37 | + wpinv_remove_discount($discount_id); |
|
38 | 38 | } |
39 | -add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' ); |
|
39 | +add_action('wpinv_delete_discount', 'wpinv_delete_discount'); |
|
40 | 40 | |
41 | -function wpinv_activate_discount( $data ) { |
|
42 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
43 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
41 | +function wpinv_activate_discount($data) { |
|
42 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
43 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
44 | 44 | } |
45 | 45 | |
46 | - if( ! current_user_can( 'manage_options' ) ) { |
|
47 | - wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
46 | + if (!current_user_can('manage_options')) { |
|
47 | + wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
48 | 48 | } |
49 | 49 | |
50 | - $id = absint( $data['discount'] ); |
|
51 | - wpinv_update_discount_status( $id, 'publish' ); |
|
50 | + $id = absint($data['discount']); |
|
51 | + wpinv_update_discount_status($id, 'publish'); |
|
52 | 52 | } |
53 | -add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' ); |
|
53 | +add_action('wpinv_activate_discount', 'wpinv_activate_discount'); |
|
54 | 54 | |
55 | -function wpinv_deactivate_discount( $data ) { |
|
56 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
57 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
55 | +function wpinv_deactivate_discount($data) { |
|
56 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
57 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
58 | 58 | } |
59 | 59 | |
60 | - if( ! current_user_can( 'manage_options' ) ) { |
|
61 | - wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) ); |
|
60 | + if (!current_user_can('manage_options')) { |
|
61 | + wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403)); |
|
62 | 62 | } |
63 | 63 | |
64 | - $id = absint( $data['discount'] ); |
|
65 | - wpinv_update_discount_status( $id, 'pending' ); |
|
64 | + $id = absint($data['discount']); |
|
65 | + wpinv_update_discount_status($id, 'pending'); |
|
66 | 66 | } |
67 | -add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
67 | +add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount'); |
|
68 | 68 | |
69 | -function wpinv_get_discounts( $args = array() ) { |
|
69 | +function wpinv_get_discounts($args = array()) { |
|
70 | 70 | $defaults = array( |
71 | 71 | 'post_type' => 'wpi_discount', |
72 | 72 | 'posts_per_page' => 20, |
73 | 73 | 'paged' => null, |
74 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
74 | + 'post_status' => array('publish', 'pending', 'draft', 'expired') |
|
75 | 75 | ); |
76 | 76 | |
77 | - $args = wp_parse_args( $args, $defaults ); |
|
77 | + $args = wp_parse_args($args, $defaults); |
|
78 | 78 | |
79 | - $discounts = get_posts( $args ); |
|
79 | + $discounts = get_posts($args); |
|
80 | 80 | |
81 | - if ( $discounts ) { |
|
81 | + if ($discounts) { |
|
82 | 82 | return $discounts; |
83 | 83 | } |
84 | 84 | |
85 | - if( ! $discounts && ! empty( $args['s'] ) ) { |
|
85 | + if (!$discounts && !empty($args['s'])) { |
|
86 | 86 | $args['meta_key'] = '_wpi_discount_code'; |
87 | 87 | $args['meta_value'] = $args['s']; |
88 | 88 | $args['meta_compare'] = 'LIKE'; |
89 | - unset( $args['s'] ); |
|
90 | - $discounts = get_posts( $args ); |
|
89 | + unset($args['s']); |
|
90 | + $discounts = get_posts($args); |
|
91 | 91 | } |
92 | 92 | |
93 | - if( $discounts ) { |
|
93 | + if ($discounts) { |
|
94 | 94 | return $discounts; |
95 | 95 | } |
96 | 96 | |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | |
103 | 103 | $discounts = wpinv_get_discounts(); |
104 | 104 | |
105 | - if ( $discounts) { |
|
106 | - foreach ( $discounts as $discount ) { |
|
107 | - if ( wpinv_is_discount_active( $discount->ID ) ) { |
|
105 | + if ($discounts) { |
|
106 | + foreach ($discounts as $discount) { |
|
107 | + if (wpinv_is_discount_active($discount->ID)) { |
|
108 | 108 | $has_active = true; |
109 | 109 | break; |
110 | 110 | } |
@@ -113,38 +113,38 @@ discard block |
||
113 | 113 | return $has_active; |
114 | 114 | } |
115 | 115 | |
116 | -function wpinv_get_discount( $discount_id = 0 ) { |
|
117 | - if( empty( $discount_id ) ) { |
|
116 | +function wpinv_get_discount($discount_id = 0) { |
|
117 | + if (empty($discount_id)) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
121 | - if ( get_post_type( $discount_id ) != 'wpi_discount' ) { |
|
121 | + if (get_post_type($discount_id) != 'wpi_discount') { |
|
122 | 122 | return false; |
123 | 123 | } |
124 | 124 | |
125 | - $discount = get_post( $discount_id ); |
|
125 | + $discount = get_post($discount_id); |
|
126 | 126 | |
127 | 127 | return $discount; |
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_get_discount_by_code( $code = '' ) { |
|
131 | - if( empty( $code ) || ! is_string( $code ) ) { |
|
130 | +function wpinv_get_discount_by_code($code = '') { |
|
131 | + if (empty($code) || !is_string($code)) { |
|
132 | 132 | return false; |
133 | 133 | } |
134 | 134 | |
135 | - return wpinv_get_discount_by( 'code', $code ); |
|
135 | + return wpinv_get_discount_by('code', $code); |
|
136 | 136 | } |
137 | 137 | |
138 | -function wpinv_get_discount_by( $field = '', $value = '' ) { |
|
139 | - if( empty( $field ) || empty( $value ) ) { |
|
138 | +function wpinv_get_discount_by($field = '', $value = '') { |
|
139 | + if (empty($field) || empty($value)) { |
|
140 | 140 | return false; |
141 | 141 | } |
142 | 142 | |
143 | - if( ! is_string( $field ) ) { |
|
143 | + if (!is_string($field)) { |
|
144 | 144 | return false; |
145 | 145 | } |
146 | 146 | |
147 | - switch( strtolower( $field ) ) { |
|
147 | + switch (strtolower($field)) { |
|
148 | 148 | |
149 | 149 | case 'code': |
150 | 150 | $meta_query = array(); |
@@ -154,32 +154,32 @@ discard block |
||
154 | 154 | 'compare' => '=' |
155 | 155 | ); |
156 | 156 | |
157 | - $discount = wpinv_get_discounts( array( |
|
157 | + $discount = wpinv_get_discounts(array( |
|
158 | 158 | 'posts_per_page' => 1, |
159 | 159 | 'post_status' => 'any', |
160 | 160 | 'meta_query' => $meta_query, |
161 | - ) ); |
|
161 | + )); |
|
162 | 162 | |
163 | - if( $discount ) { |
|
163 | + if ($discount) { |
|
164 | 164 | $discount = $discount[0]; |
165 | 165 | } |
166 | 166 | |
167 | 167 | break; |
168 | 168 | |
169 | 169 | case 'id': |
170 | - $discount = wpinv_get_discount( $value ); |
|
170 | + $discount = wpinv_get_discount($value); |
|
171 | 171 | |
172 | 172 | break; |
173 | 173 | |
174 | 174 | case 'name': |
175 | - $discount = get_posts( array( |
|
175 | + $discount = get_posts(array( |
|
176 | 176 | 'post_type' => 'wpi_discount', |
177 | 177 | 'name' => $value, |
178 | 178 | 'posts_per_page' => 1, |
179 | 179 | 'post_status' => 'any' |
180 | - ) ); |
|
180 | + )); |
|
181 | 181 | |
182 | - if( $discount ) { |
|
182 | + if ($discount) { |
|
183 | 183 | $discount = $discount[0]; |
184 | 184 | } |
185 | 185 | |
@@ -189,96 +189,96 @@ discard block |
||
189 | 189 | return false; |
190 | 190 | } |
191 | 191 | |
192 | - if( ! empty( $discount ) ) { |
|
192 | + if (!empty($discount)) { |
|
193 | 193 | return $discount; |
194 | 194 | } |
195 | 195 | |
196 | 196 | return false; |
197 | 197 | } |
198 | 198 | |
199 | -function wpinv_store_discount( $post_id, $data, $post, $update = false ) { |
|
199 | +function wpinv_store_discount($post_id, $data, $post, $update = false) { |
|
200 | 200 | $meta = array( |
201 | - 'code' => isset( $data['code'] ) ? sanitize_text_field( $data['code'] ) : '', |
|
202 | - 'type' => isset( $data['type'] ) ? sanitize_text_field( $data['type'] ) : 'percent', |
|
203 | - 'amount' => isset( $data['amount'] ) ? wpinv_sanitize_amount( $data['amount'] ) : '', |
|
204 | - 'start' => isset( $data['start'] ) ? sanitize_text_field( $data['start'] ) : '', |
|
205 | - 'expiration' => isset( $data['expiration'] ) ? sanitize_text_field( $data['expiration'] ) : '', |
|
206 | - 'min_total' => isset( $data['min_total'] ) ? wpinv_sanitize_amount( $data['min_total'] ) : '', |
|
207 | - 'max_total' => isset( $data['max_total'] ) ? wpinv_sanitize_amount( $data['max_total'] ) : '', |
|
208 | - 'max_uses' => isset( $data['max_uses'] ) ? absint( $data['max_uses'] ) : '', |
|
209 | - 'items' => isset( $data['items'] ) ? $data['items'] : array(), |
|
210 | - 'excluded_items' => isset( $data['excluded_items'] ) ? $data['excluded_items'] : array(), |
|
211 | - 'is_recurring' => isset( $data['recurring'] ) ? (bool)$data['recurring'] : false, |
|
212 | - 'is_single_use' => isset( $data['single_use'] ) ? (bool)$data['single_use'] : false, |
|
213 | - 'uses' => isset( $data['uses'] ) ? (int)$data['uses'] : false, |
|
201 | + 'code' => isset($data['code']) ? sanitize_text_field($data['code']) : '', |
|
202 | + 'type' => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent', |
|
203 | + 'amount' => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '', |
|
204 | + 'start' => isset($data['start']) ? sanitize_text_field($data['start']) : '', |
|
205 | + 'expiration' => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '', |
|
206 | + 'min_total' => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '', |
|
207 | + 'max_total' => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '', |
|
208 | + 'max_uses' => isset($data['max_uses']) ? absint($data['max_uses']) : '', |
|
209 | + 'items' => isset($data['items']) ? $data['items'] : array(), |
|
210 | + 'excluded_items' => isset($data['excluded_items']) ? $data['excluded_items'] : array(), |
|
211 | + 'is_recurring' => isset($data['recurring']) ? (bool)$data['recurring'] : false, |
|
212 | + 'is_single_use' => isset($data['single_use']) ? (bool)$data['single_use'] : false, |
|
213 | + 'uses' => isset($data['uses']) ? (int)$data['uses'] : false, |
|
214 | 214 | ); |
215 | 215 | |
216 | - if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) { |
|
216 | + if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) { |
|
217 | 217 | $meta['amount'] = 100; |
218 | 218 | } |
219 | 219 | |
220 | - if ( !empty( $meta['start'] ) ) { |
|
221 | - $meta['start'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) ); |
|
220 | + if (!empty($meta['start'])) { |
|
221 | + $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start'])); |
|
222 | 222 | } |
223 | 223 | |
224 | - if ( !empty( $meta['expiration'] ) ) { |
|
225 | - $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) ); |
|
224 | + if (!empty($meta['expiration'])) { |
|
225 | + $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration'])); |
|
226 | 226 | |
227 | - if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) { |
|
227 | + if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) { |
|
228 | 228 | $meta['expiration'] = $meta['start']; |
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | - if ( $meta['uses'] === false ) { |
|
233 | - unset( $meta['uses'] ); |
|
232 | + if ($meta['uses'] === false) { |
|
233 | + unset($meta['uses']); |
|
234 | 234 | } |
235 | 235 | |
236 | - if ( ! empty( $meta['items'] ) ) { |
|
237 | - foreach ( $meta['items'] as $key => $item ) { |
|
238 | - if ( 0 === intval( $item ) ) { |
|
239 | - unset( $meta['items'][ $key ] ); |
|
236 | + if (!empty($meta['items'])) { |
|
237 | + foreach ($meta['items'] as $key => $item) { |
|
238 | + if (0 === intval($item)) { |
|
239 | + unset($meta['items'][$key]); |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | } |
243 | 243 | |
244 | - if ( ! empty( $meta['excluded_items'] ) ) { |
|
245 | - foreach ( $meta['excluded_items'] as $key => $item ) { |
|
246 | - if ( 0 === intval( $item ) ) { |
|
247 | - unset( $meta['excluded_items'][ $key ] ); |
|
244 | + if (!empty($meta['excluded_items'])) { |
|
245 | + foreach ($meta['excluded_items'] as $key => $item) { |
|
246 | + if (0 === intval($item)) { |
|
247 | + unset($meta['excluded_items'][$key]); |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | - $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post ); |
|
252 | + $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post); |
|
253 | 253 | |
254 | - do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post ); |
|
254 | + do_action('wpinv_pre_update_discount', $meta, $post_id, $post); |
|
255 | 255 | |
256 | - foreach( $meta as $key => $value ) { |
|
257 | - update_post_meta( $post_id, '_wpi_discount_' . $key, $value ); |
|
256 | + foreach ($meta as $key => $value) { |
|
257 | + update_post_meta($post_id, '_wpi_discount_' . $key, $value); |
|
258 | 258 | } |
259 | 259 | |
260 | - do_action( 'wpinv_post_update_discount', $meta, $post_id, $post ); |
|
260 | + do_action('wpinv_post_update_discount', $meta, $post_id, $post); |
|
261 | 261 | |
262 | 262 | return $post_id; |
263 | 263 | } |
264 | 264 | |
265 | -function wpinv_remove_discount( $discount_id = 0 ) { |
|
266 | - do_action( 'wpinv_pre_delete_discount', $discount_id ); |
|
265 | +function wpinv_remove_discount($discount_id = 0) { |
|
266 | + do_action('wpinv_pre_delete_discount', $discount_id); |
|
267 | 267 | |
268 | - wp_delete_post( $discount_id, true ); |
|
268 | + wp_delete_post($discount_id, true); |
|
269 | 269 | |
270 | - do_action( 'wpinv_post_delete_discount', $discount_id ); |
|
270 | + do_action('wpinv_post_delete_discount', $discount_id); |
|
271 | 271 | } |
272 | 272 | |
273 | -function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) { |
|
274 | - $discount = wpinv_get_discount( $code_id ); |
|
273 | +function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') { |
|
274 | + $discount = wpinv_get_discount($code_id); |
|
275 | 275 | |
276 | - if ( $discount ) { |
|
277 | - do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
276 | + if ($discount) { |
|
277 | + do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
278 | 278 | |
279 | - wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) ); |
|
279 | + wp_update_post(array('ID' => $code_id, 'post_status' => $new_status)); |
|
280 | 280 | |
281 | - do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
281 | + do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
282 | 282 | |
283 | 283 | return true; |
284 | 284 | } |
@@ -286,173 +286,173 @@ discard block |
||
286 | 286 | return false; |
287 | 287 | } |
288 | 288 | |
289 | -function wpinv_discount_exists( $code_id ) { |
|
290 | - if ( wpinv_get_discount( $code_id ) ) { |
|
289 | +function wpinv_discount_exists($code_id) { |
|
290 | + if (wpinv_get_discount($code_id)) { |
|
291 | 291 | return true; |
292 | 292 | } |
293 | 293 | |
294 | 294 | return false; |
295 | 295 | } |
296 | 296 | |
297 | -function wpinv_is_discount_active( $code_id = null ) { |
|
298 | - $discount = wpinv_get_discount( $code_id ); |
|
297 | +function wpinv_is_discount_active($code_id = null) { |
|
298 | + $discount = wpinv_get_discount($code_id); |
|
299 | 299 | $return = false; |
300 | 300 | |
301 | - if ( $discount ) { |
|
302 | - if ( wpinv_is_discount_expired( $code_id ) ) { |
|
303 | - if( defined( 'DOING_AJAX' ) ) { |
|
304 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) ); |
|
301 | + if ($discount) { |
|
302 | + if (wpinv_is_discount_expired($code_id)) { |
|
303 | + if (defined('DOING_AJAX')) { |
|
304 | + wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing')); |
|
305 | 305 | } |
306 | - } elseif ( $discount->post_status == 'publish' ) { |
|
306 | + } elseif ($discount->post_status == 'publish') { |
|
307 | 307 | $return = true; |
308 | 308 | } else { |
309 | - if( defined( 'DOING_AJAX' ) ) { |
|
310 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) ); |
|
309 | + if (defined('DOING_AJAX')) { |
|
310 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing')); |
|
311 | 311 | } |
312 | 312 | } |
313 | 313 | } |
314 | 314 | |
315 | - return apply_filters( 'wpinv_is_discount_active', $return, $code_id ); |
|
315 | + return apply_filters('wpinv_is_discount_active', $return, $code_id); |
|
316 | 316 | } |
317 | 317 | |
318 | -function wpinv_get_discount_code( $code_id = null ) { |
|
319 | - $code = get_post_meta( $code_id, '_wpi_discount_code', true ); |
|
318 | +function wpinv_get_discount_code($code_id = null) { |
|
319 | + $code = get_post_meta($code_id, '_wpi_discount_code', true); |
|
320 | 320 | |
321 | - return apply_filters( 'wpinv_get_discount_code', $code, $code_id ); |
|
321 | + return apply_filters('wpinv_get_discount_code', $code, $code_id); |
|
322 | 322 | } |
323 | 323 | |
324 | -function wpinv_get_discount_start_date( $code_id = null ) { |
|
325 | - $start_date = get_post_meta( $code_id, '_wpi_discount_start', true ); |
|
324 | +function wpinv_get_discount_start_date($code_id = null) { |
|
325 | + $start_date = get_post_meta($code_id, '_wpi_discount_start', true); |
|
326 | 326 | |
327 | - return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id ); |
|
327 | + return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id); |
|
328 | 328 | } |
329 | 329 | |
330 | -function wpinv_get_discount_expiration( $code_id = null ) { |
|
331 | - $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true ); |
|
330 | +function wpinv_get_discount_expiration($code_id = null) { |
|
331 | + $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true); |
|
332 | 332 | |
333 | - return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id ); |
|
333 | + return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id); |
|
334 | 334 | } |
335 | 335 | |
336 | -function wpinv_get_discount_max_uses( $code_id = null ) { |
|
337 | - $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true ); |
|
336 | +function wpinv_get_discount_max_uses($code_id = null) { |
|
337 | + $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true); |
|
338 | 338 | |
339 | - return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id ); |
|
339 | + return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id); |
|
340 | 340 | } |
341 | 341 | |
342 | -function wpinv_get_discount_uses( $code_id = null ) { |
|
343 | - $uses = get_post_meta( $code_id, '_wpi_discount_uses', true ); |
|
342 | +function wpinv_get_discount_uses($code_id = null) { |
|
343 | + $uses = get_post_meta($code_id, '_wpi_discount_uses', true); |
|
344 | 344 | |
345 | - return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id ); |
|
345 | + return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id); |
|
346 | 346 | } |
347 | 347 | |
348 | -function wpinv_get_discount_min_total( $code_id = null ) { |
|
349 | - $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true ); |
|
348 | +function wpinv_get_discount_min_total($code_id = null) { |
|
349 | + $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true); |
|
350 | 350 | |
351 | - return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id ); |
|
351 | + return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id); |
|
352 | 352 | } |
353 | 353 | |
354 | -function wpinv_get_discount_max_total( $code_id = null ) { |
|
355 | - $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true ); |
|
354 | +function wpinv_get_discount_max_total($code_id = null) { |
|
355 | + $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true); |
|
356 | 356 | |
357 | - return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id ); |
|
357 | + return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id); |
|
358 | 358 | } |
359 | 359 | |
360 | -function wpinv_get_discount_amount( $code_id = null ) { |
|
361 | - $amount = get_post_meta( $code_id, '_wpi_discount_amount', true ); |
|
360 | +function wpinv_get_discount_amount($code_id = null) { |
|
361 | + $amount = get_post_meta($code_id, '_wpi_discount_amount', true); |
|
362 | 362 | |
363 | - return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id ); |
|
363 | + return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id); |
|
364 | 364 | } |
365 | 365 | |
366 | -function wpinv_get_discount_type( $code_id = null, $name = false ) { |
|
367 | - $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) ); |
|
366 | +function wpinv_get_discount_type($code_id = null, $name = false) { |
|
367 | + $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true)); |
|
368 | 368 | |
369 | - if ( $name ) { |
|
370 | - $name = wpinv_get_discount_type_name( $type ); |
|
369 | + if ($name) { |
|
370 | + $name = wpinv_get_discount_type_name($type); |
|
371 | 371 | |
372 | - return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id ); |
|
372 | + return apply_filters('wpinv_get_discount_type_name', $name, $code_id); |
|
373 | 373 | } |
374 | 374 | |
375 | - return apply_filters( 'wpinv_get_discount_type', $type, $code_id ); |
|
375 | + return apply_filters('wpinv_get_discount_type', $type, $code_id); |
|
376 | 376 | } |
377 | 377 | |
378 | -function wpinv_discount_status( $status ) { |
|
379 | - switch( $status ){ |
|
378 | +function wpinv_discount_status($status) { |
|
379 | + switch ($status) { |
|
380 | 380 | case 'expired' : |
381 | - $name = __( 'Expired', 'invoicing' ); |
|
381 | + $name = __('Expired', 'invoicing'); |
|
382 | 382 | break; |
383 | 383 | case 'publish' : |
384 | 384 | case 'active' : |
385 | - $name = __( 'Active', 'invoicing' ); |
|
385 | + $name = __('Active', 'invoicing'); |
|
386 | 386 | break; |
387 | 387 | default : |
388 | - $name = __( 'Inactive', 'invoicing' ); |
|
388 | + $name = __('Inactive', 'invoicing'); |
|
389 | 389 | break; |
390 | 390 | } |
391 | 391 | return $name; |
392 | 392 | } |
393 | 393 | |
394 | -function wpinv_get_discount_excluded_items( $code_id = null ) { |
|
395 | - $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true ); |
|
394 | +function wpinv_get_discount_excluded_items($code_id = null) { |
|
395 | + $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true); |
|
396 | 396 | |
397 | - if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) { |
|
397 | + if (empty($excluded_items) || !is_array($excluded_items)) { |
|
398 | 398 | $excluded_items = array(); |
399 | 399 | } |
400 | 400 | |
401 | - return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id ); |
|
401 | + return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id); |
|
402 | 402 | } |
403 | 403 | |
404 | -function wpinv_get_discount_item_reqs( $code_id = null ) { |
|
405 | - $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true ); |
|
404 | +function wpinv_get_discount_item_reqs($code_id = null) { |
|
405 | + $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true); |
|
406 | 406 | |
407 | - if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) { |
|
407 | + if (empty($item_reqs) || !is_array($item_reqs)) { |
|
408 | 408 | $item_reqs = array(); |
409 | 409 | } |
410 | 410 | |
411 | - return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id ); |
|
411 | + return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id); |
|
412 | 412 | } |
413 | 413 | |
414 | -function wpinv_get_discount_item_condition( $code_id = 0 ) { |
|
415 | - return get_post_meta( $code_id, '_wpi_discount_item_condition', true ); |
|
414 | +function wpinv_get_discount_item_condition($code_id = 0) { |
|
415 | + return get_post_meta($code_id, '_wpi_discount_item_condition', true); |
|
416 | 416 | } |
417 | 417 | |
418 | -function wpinv_is_discount_not_global( $code_id = 0 ) { |
|
419 | - return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true ); |
|
418 | +function wpinv_is_discount_not_global($code_id = 0) { |
|
419 | + return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true); |
|
420 | 420 | } |
421 | 421 | |
422 | -function wpinv_is_discount_expired( $code_id = null ) { |
|
423 | - $discount = wpinv_get_discount( $code_id ); |
|
422 | +function wpinv_is_discount_expired($code_id = null) { |
|
423 | + $discount = wpinv_get_discount($code_id); |
|
424 | 424 | $return = false; |
425 | 425 | |
426 | - if ( $discount ) { |
|
427 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
428 | - if ( $expiration ) { |
|
429 | - $expiration = strtotime( $expiration ); |
|
430 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
426 | + if ($discount) { |
|
427 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
428 | + if ($expiration) { |
|
429 | + $expiration = strtotime($expiration); |
|
430 | + if ($expiration < current_time('timestamp')) { |
|
431 | 431 | // Discount is expired |
432 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
432 | + wpinv_update_discount_status($code_id, 'pending'); |
|
433 | 433 | $return = true; |
434 | 434 | } |
435 | 435 | } |
436 | 436 | } |
437 | 437 | |
438 | - return apply_filters( 'wpinv_is_discount_expired', $return, $code_id ); |
|
438 | + return apply_filters('wpinv_is_discount_expired', $return, $code_id); |
|
439 | 439 | } |
440 | 440 | |
441 | -function wpinv_is_discount_started( $code_id = null ) { |
|
442 | - $discount = wpinv_get_discount( $code_id ); |
|
441 | +function wpinv_is_discount_started($code_id = null) { |
|
442 | + $discount = wpinv_get_discount($code_id); |
|
443 | 443 | $return = false; |
444 | 444 | |
445 | - if ( $discount ) { |
|
446 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
445 | + if ($discount) { |
|
446 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
447 | 447 | |
448 | - if ( $start_date ) { |
|
449 | - $start_date = strtotime( $start_date ); |
|
448 | + if ($start_date) { |
|
449 | + $start_date = strtotime($start_date); |
|
450 | 450 | |
451 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
451 | + if ($start_date < current_time('timestamp')) { |
|
452 | 452 | // Discount has past the start date |
453 | 453 | $return = true; |
454 | 454 | } else { |
455 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
455 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
456 | 456 | } |
457 | 457 | } else { |
458 | 458 | // No start date for this discount, so has to be true |
@@ -460,159 +460,159 @@ discard block |
||
460 | 460 | } |
461 | 461 | } |
462 | 462 | |
463 | - return apply_filters( 'wpinv_is_discount_started', $return, $code_id ); |
|
463 | + return apply_filters('wpinv_is_discount_started', $return, $code_id); |
|
464 | 464 | } |
465 | 465 | |
466 | -function wpinv_check_discount_dates( $code_id = null ) { |
|
467 | - $discount = wpinv_get_discount( $code_id ); |
|
466 | +function wpinv_check_discount_dates($code_id = null) { |
|
467 | + $discount = wpinv_get_discount($code_id); |
|
468 | 468 | $return = false; |
469 | 469 | |
470 | - if ( $discount ) { |
|
471 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
470 | + if ($discount) { |
|
471 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
472 | 472 | |
473 | - if ( $start_date ) { |
|
474 | - $start_date = strtotime( $start_date ); |
|
473 | + if ($start_date) { |
|
474 | + $start_date = strtotime($start_date); |
|
475 | 475 | |
476 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
476 | + if ($start_date < current_time('timestamp')) { |
|
477 | 477 | // Discount has past the start date |
478 | 478 | $return = true; |
479 | 479 | } else { |
480 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
480 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
481 | 481 | } |
482 | 482 | } else { |
483 | 483 | // No start date for this discount, so has to be true |
484 | 484 | $return = true; |
485 | 485 | } |
486 | 486 | |
487 | - if ( $return ) { |
|
488 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
487 | + if ($return) { |
|
488 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
489 | 489 | |
490 | - if ( $expiration ) { |
|
491 | - $expiration = strtotime( $expiration ); |
|
492 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
490 | + if ($expiration) { |
|
491 | + $expiration = strtotime($expiration); |
|
492 | + if ($expiration < current_time('timestamp')) { |
|
493 | 493 | // Discount is expired |
494 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
494 | + wpinv_update_discount_status($code_id, 'pending'); |
|
495 | 495 | $return = true; |
496 | 496 | } |
497 | 497 | } |
498 | 498 | } |
499 | 499 | } |
500 | 500 | |
501 | - return apply_filters( 'wpinv_check_discount_dates', $return, $code_id ); |
|
501 | + return apply_filters('wpinv_check_discount_dates', $return, $code_id); |
|
502 | 502 | } |
503 | 503 | |
504 | -function wpinv_is_discount_maxed_out( $code_id = null ) { |
|
505 | - $discount = wpinv_get_discount( $code_id ); |
|
504 | +function wpinv_is_discount_maxed_out($code_id = null) { |
|
505 | + $discount = wpinv_get_discount($code_id); |
|
506 | 506 | $return = false; |
507 | 507 | |
508 | - if ( $discount ) { |
|
509 | - $uses = wpinv_get_discount_uses( $code_id ); |
|
508 | + if ($discount) { |
|
509 | + $uses = wpinv_get_discount_uses($code_id); |
|
510 | 510 | // Large number that will never be reached |
511 | - $max_uses = wpinv_get_discount_max_uses( $code_id ); |
|
511 | + $max_uses = wpinv_get_discount_max_uses($code_id); |
|
512 | 512 | // Should never be greater than, but just in case |
513 | - if ( $uses >= $max_uses && ! empty( $max_uses ) ) { |
|
513 | + if ($uses >= $max_uses && !empty($max_uses)) { |
|
514 | 514 | // Discount is maxed out |
515 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) ); |
|
515 | + wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing')); |
|
516 | 516 | $return = true; |
517 | 517 | } |
518 | 518 | } |
519 | 519 | |
520 | - return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id ); |
|
520 | + return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id); |
|
521 | 521 | } |
522 | 522 | |
523 | -function wpinv_discount_is_min_met( $code_id = null ) { |
|
524 | - $discount = wpinv_get_discount( $code_id ); |
|
523 | +function wpinv_discount_is_min_met($code_id = null) { |
|
524 | + $discount = wpinv_get_discount($code_id); |
|
525 | 525 | $return = false; |
526 | 526 | |
527 | - if ( $discount ) { |
|
528 | - $min = (float)wpinv_get_discount_min_total( $code_id ); |
|
529 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
527 | + if ($discount) { |
|
528 | + $min = (float)wpinv_get_discount_min_total($code_id); |
|
529 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
530 | 530 | |
531 | - if ( !$min > 0 || $cart_amount >= $min ) { |
|
531 | + if (!$min > 0 || $cart_amount >= $min) { |
|
532 | 532 | // Minimum has been met |
533 | 533 | $return = true; |
534 | 534 | } else { |
535 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) ); |
|
535 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min)))); |
|
536 | 536 | } |
537 | 537 | } |
538 | 538 | |
539 | - return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id ); |
|
539 | + return apply_filters('wpinv_is_discount_min_met', $return, $code_id); |
|
540 | 540 | } |
541 | 541 | |
542 | -function wpinv_discount_is_max_met( $code_id = null ) { |
|
543 | - $discount = wpinv_get_discount( $code_id ); |
|
542 | +function wpinv_discount_is_max_met($code_id = null) { |
|
543 | + $discount = wpinv_get_discount($code_id); |
|
544 | 544 | $return = false; |
545 | 545 | |
546 | - if ( $discount ) { |
|
547 | - $max = (float)wpinv_get_discount_max_total( $code_id ); |
|
548 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
546 | + if ($discount) { |
|
547 | + $max = (float)wpinv_get_discount_max_total($code_id); |
|
548 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
549 | 549 | |
550 | - if ( !$max > 0 || $cart_amount <= $max ) { |
|
550 | + if (!$max > 0 || $cart_amount <= $max) { |
|
551 | 551 | // Minimum has been met |
552 | 552 | $return = true; |
553 | 553 | } else { |
554 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) ); |
|
554 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max)))); |
|
555 | 555 | } |
556 | 556 | } |
557 | 557 | |
558 | - return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id ); |
|
558 | + return apply_filters('wpinv_is_discount_max_met', $return, $code_id); |
|
559 | 559 | } |
560 | 560 | |
561 | -function wpinv_discount_is_single_use( $code_id = 0 ) { |
|
562 | - $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true ); |
|
563 | - return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id ); |
|
561 | +function wpinv_discount_is_single_use($code_id = 0) { |
|
562 | + $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true); |
|
563 | + return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id); |
|
564 | 564 | } |
565 | 565 | |
566 | -function wpinv_discount_is_recurring( $code_id = 0, $code = false ) { |
|
567 | - if ( $code ) { |
|
568 | - $discount = wpinv_get_discount_by_code( $code_id ); |
|
566 | +function wpinv_discount_is_recurring($code_id = 0, $code = false) { |
|
567 | + if ($code) { |
|
568 | + $discount = wpinv_get_discount_by_code($code_id); |
|
569 | 569 | |
570 | - if ( !empty( $discount ) ) { |
|
570 | + if (!empty($discount)) { |
|
571 | 571 | $code_id = $discount->ID; |
572 | 572 | } |
573 | 573 | } |
574 | 574 | |
575 | - $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true ); |
|
575 | + $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true); |
|
576 | 576 | |
577 | - return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code ); |
|
577 | + return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code); |
|
578 | 578 | } |
579 | 579 | |
580 | -function wpinv_discount_item_reqs_met( $code_id = null ) { |
|
581 | - $item_reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
582 | - $condition = wpinv_get_discount_item_condition( $code_id ); |
|
583 | - $excluded_ps = wpinv_get_discount_excluded_items( $code_id ); |
|
580 | +function wpinv_discount_item_reqs_met($code_id = null) { |
|
581 | + $item_reqs = wpinv_get_discount_item_reqs($code_id); |
|
582 | + $condition = wpinv_get_discount_item_condition($code_id); |
|
583 | + $excluded_ps = wpinv_get_discount_excluded_items($code_id); |
|
584 | 584 | $cart_items = wpinv_get_cart_contents(); |
585 | - $cart_ids = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null; |
|
585 | + $cart_ids = $cart_items ? wp_list_pluck($cart_items, 'id') : null; |
|
586 | 586 | $ret = false; |
587 | 587 | |
588 | - if ( empty( $item_reqs ) && empty( $excluded_ps ) ) { |
|
588 | + if (empty($item_reqs) && empty($excluded_ps)) { |
|
589 | 589 | $ret = true; |
590 | 590 | } |
591 | 591 | |
592 | 592 | // Normalize our data for item requirements, exclusions and cart data |
593 | 593 | // First absint the items, then sort, and reset the array keys |
594 | - $item_reqs = array_map( 'absint', $item_reqs ); |
|
595 | - asort( $item_reqs ); |
|
596 | - $item_reqs = array_values( $item_reqs ); |
|
594 | + $item_reqs = array_map('absint', $item_reqs); |
|
595 | + asort($item_reqs); |
|
596 | + $item_reqs = array_values($item_reqs); |
|
597 | 597 | |
598 | - $excluded_ps = array_map( 'absint', $excluded_ps ); |
|
599 | - asort( $excluded_ps ); |
|
600 | - $excluded_ps = array_values( $excluded_ps ); |
|
598 | + $excluded_ps = array_map('absint', $excluded_ps); |
|
599 | + asort($excluded_ps); |
|
600 | + $excluded_ps = array_values($excluded_ps); |
|
601 | 601 | |
602 | - $cart_ids = array_map( 'absint', $cart_ids ); |
|
603 | - asort( $cart_ids ); |
|
604 | - $cart_ids = array_values( $cart_ids ); |
|
602 | + $cart_ids = array_map('absint', $cart_ids); |
|
603 | + asort($cart_ids); |
|
604 | + $cart_ids = array_values($cart_ids); |
|
605 | 605 | |
606 | 606 | // Ensure we have requirements before proceeding |
607 | - if ( !$ret && ! empty( $item_reqs ) ) { |
|
608 | - switch( $condition ) { |
|
607 | + if (!$ret && !empty($item_reqs)) { |
|
608 | + switch ($condition) { |
|
609 | 609 | case 'all' : |
610 | 610 | // Default back to true |
611 | 611 | $ret = true; |
612 | 612 | |
613 | - foreach ( $item_reqs as $item_id ) { |
|
614 | - if ( !wpinv_item_in_cart( $item_id ) ) { |
|
615 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
613 | + foreach ($item_reqs as $item_id) { |
|
614 | + if (!wpinv_item_in_cart($item_id)) { |
|
615 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
616 | 616 | $ret = false; |
617 | 617 | break; |
618 | 618 | } |
@@ -621,15 +621,15 @@ discard block |
||
621 | 621 | break; |
622 | 622 | |
623 | 623 | default : // Any |
624 | - foreach ( $item_reqs as $item_id ) { |
|
625 | - if ( wpinv_item_in_cart( $item_id ) ) { |
|
624 | + foreach ($item_reqs as $item_id) { |
|
625 | + if (wpinv_item_in_cart($item_id)) { |
|
626 | 626 | $ret = true; |
627 | 627 | break; |
628 | 628 | } |
629 | 629 | } |
630 | 630 | |
631 | - if( ! $ret ) { |
|
632 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
631 | + if (!$ret) { |
|
632 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | break; |
@@ -638,70 +638,70 @@ discard block |
||
638 | 638 | $ret = true; |
639 | 639 | } |
640 | 640 | |
641 | - if( ! empty( $excluded_ps ) ) { |
|
641 | + if (!empty($excluded_ps)) { |
|
642 | 642 | // Check that there are items other than excluded ones in the cart |
643 | - if( $cart_ids == $excluded_ps ) { |
|
644 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) ); |
|
643 | + if ($cart_ids == $excluded_ps) { |
|
644 | + wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing')); |
|
645 | 645 | $ret = false; |
646 | 646 | } |
647 | 647 | } |
648 | 648 | |
649 | - return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition ); |
|
649 | + return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition); |
|
650 | 650 | } |
651 | 651 | |
652 | -function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) { |
|
652 | +function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) { |
|
653 | 653 | global $wpi_checkout_id; |
654 | 654 | |
655 | 655 | $return = false; |
656 | 656 | |
657 | - if ( empty( $code_id ) ) { |
|
658 | - $code_id = wpinv_get_discount_id_by_code( $code ); |
|
657 | + if (empty($code_id)) { |
|
658 | + $code_id = wpinv_get_discount_id_by_code($code); |
|
659 | 659 | |
660 | - if( empty( $code_id ) ) { |
|
660 | + if (empty($code_id)) { |
|
661 | 661 | return false; // No discount was found |
662 | 662 | } |
663 | 663 | } |
664 | 664 | |
665 | - if ( wpinv_discount_is_single_use( $code_id ) ) { |
|
665 | + if (wpinv_discount_is_single_use($code_id)) { |
|
666 | 666 | $payments = array(); |
667 | 667 | |
668 | 668 | $user_id = 0; |
669 | - if ( is_int( $user ) ) { |
|
670 | - $user_id = absint( $user ); |
|
671 | - } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
|
669 | + if (is_int($user)) { |
|
670 | + $user_id = absint($user); |
|
671 | + } else if (is_email($user) && $user_data = get_user_by('email', $user)) { |
|
672 | 672 | $user_id = $user_data->ID; |
673 | - } else if ( $user_data = get_user_by( 'login', $user ) ) { |
|
673 | + } else if ($user_data = get_user_by('login', $user)) { |
|
674 | 674 | $user_id = $user_data->ID; |
675 | - } else if ( absint( $user ) > 0 ) { |
|
676 | - $user_id = absint( $user ); |
|
675 | + } else if (absint($user) > 0) { |
|
676 | + $user_id = absint($user); |
|
677 | 677 | } |
678 | 678 | |
679 | - if ( !empty( $user_id ) ) { |
|
680 | - $query = array( 'user' => $user_id, 'limit' => false ); |
|
681 | - $payments = wpinv_get_invoices( $query ); // Get all payments with matching user id |
|
679 | + if (!empty($user_id)) { |
|
680 | + $query = array('user' => $user_id, 'limit' => false); |
|
681 | + $payments = wpinv_get_invoices($query); // Get all payments with matching user id |
|
682 | 682 | } |
683 | 683 | |
684 | - if ( $payments ) { |
|
685 | - foreach ( $payments as $payment ) { |
|
684 | + if ($payments) { |
|
685 | + foreach ($payments as $payment) { |
|
686 | 686 | // Don't count discount used for current invoice chekcout. |
687 | - if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) { |
|
687 | + if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) { |
|
688 | 688 | continue; |
689 | 689 | } |
690 | 690 | |
691 | - if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) { |
|
691 | + if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) { |
|
692 | 692 | continue; |
693 | 693 | } |
694 | 694 | |
695 | - $discounts = $payment->get_discounts( true ); |
|
696 | - if ( empty( $discounts ) ) { |
|
695 | + $discounts = $payment->get_discounts(true); |
|
696 | + if (empty($discounts)) { |
|
697 | 697 | continue; |
698 | 698 | } |
699 | 699 | |
700 | - $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts; |
|
700 | + $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts; |
|
701 | 701 | |
702 | - if ( !empty( $discounts ) && is_array( $discounts ) ) { |
|
703 | - if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) { |
|
704 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) ); |
|
702 | + if (!empty($discounts) && is_array($discounts)) { |
|
703 | + if (in_array(strtolower($code), array_map('strtolower', $discounts))) { |
|
704 | + wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing')); |
|
705 | 705 | $return = true; |
706 | 706 | break; |
707 | 707 | } |
@@ -710,61 +710,61 @@ discard block |
||
710 | 710 | } |
711 | 711 | } |
712 | 712 | |
713 | - return apply_filters( 'wpinv_is_discount_used', $return, $code, $user ); |
|
713 | + return apply_filters('wpinv_is_discount_used', $return, $code, $user); |
|
714 | 714 | } |
715 | 715 | |
716 | -function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) { |
|
716 | +function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) { |
|
717 | 717 | $return = false; |
718 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
719 | - $user = trim( $user ); |
|
718 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
719 | + $user = trim($user); |
|
720 | 720 | |
721 | - if ( wpinv_get_cart_contents() ) { |
|
722 | - if ( $discount_id ) { |
|
721 | + if (wpinv_get_cart_contents()) { |
|
722 | + if ($discount_id) { |
|
723 | 723 | if ( |
724 | - wpinv_is_discount_active( $discount_id ) && |
|
725 | - wpinv_check_discount_dates( $discount_id ) && |
|
726 | - !wpinv_is_discount_maxed_out( $discount_id ) && |
|
727 | - !wpinv_is_discount_used( $code, $user, $discount_id ) && |
|
728 | - wpinv_discount_is_min_met( $discount_id ) && |
|
729 | - wpinv_discount_is_max_met( $discount_id ) && |
|
730 | - wpinv_discount_item_reqs_met( $discount_id ) |
|
724 | + wpinv_is_discount_active($discount_id) && |
|
725 | + wpinv_check_discount_dates($discount_id) && |
|
726 | + !wpinv_is_discount_maxed_out($discount_id) && |
|
727 | + !wpinv_is_discount_used($code, $user, $discount_id) && |
|
728 | + wpinv_discount_is_min_met($discount_id) && |
|
729 | + wpinv_discount_is_max_met($discount_id) && |
|
730 | + wpinv_discount_item_reqs_met($discount_id) |
|
731 | 731 | ) { |
732 | 732 | $return = true; |
733 | 733 | } |
734 | - } elseif( $set_error ) { |
|
735 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) ); |
|
734 | + } elseif ($set_error) { |
|
735 | + wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing')); |
|
736 | 736 | } |
737 | 737 | } |
738 | 738 | |
739 | - return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user ); |
|
739 | + return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user); |
|
740 | 740 | } |
741 | 741 | |
742 | -function wpinv_get_discount_id_by_code( $code ) { |
|
743 | - $discount = wpinv_get_discount_by_code( $code ); |
|
744 | - if( $discount ) { |
|
742 | +function wpinv_get_discount_id_by_code($code) { |
|
743 | + $discount = wpinv_get_discount_by_code($code); |
|
744 | + if ($discount) { |
|
745 | 745 | return $discount->ID; |
746 | 746 | } |
747 | 747 | return false; |
748 | 748 | } |
749 | 749 | |
750 | -function wpinv_get_discounted_amount( $code, $base_price ) { |
|
750 | +function wpinv_get_discounted_amount($code, $base_price) { |
|
751 | 751 | $amount = $base_price; |
752 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
752 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
753 | 753 | |
754 | - if( $discount_id ) { |
|
755 | - $type = wpinv_get_discount_type( $discount_id ); |
|
756 | - $rate = wpinv_get_discount_amount( $discount_id ); |
|
754 | + if ($discount_id) { |
|
755 | + $type = wpinv_get_discount_type($discount_id); |
|
756 | + $rate = wpinv_get_discount_amount($discount_id); |
|
757 | 757 | |
758 | - if ( $type == 'flat' ) { |
|
758 | + if ($type == 'flat') { |
|
759 | 759 | // Set amount |
760 | 760 | $amount = $base_price - $rate; |
761 | - if ( $amount < 0 ) { |
|
761 | + if ($amount < 0) { |
|
762 | 762 | $amount = 0; |
763 | 763 | } |
764 | 764 | |
765 | 765 | } else { |
766 | 766 | // Percentage discount |
767 | - $amount = $base_price - ( $base_price * ( $rate / 100 ) ); |
|
767 | + $amount = $base_price - ($base_price * ($rate / 100)); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | } else { |
@@ -773,108 +773,108 @@ discard block |
||
773 | 773 | |
774 | 774 | } |
775 | 775 | |
776 | - return apply_filters( 'wpinv_discounted_amount', $amount ); |
|
776 | + return apply_filters('wpinv_discounted_amount', $amount); |
|
777 | 777 | } |
778 | 778 | |
779 | -function wpinv_increase_discount_usage( $code ) { |
|
779 | +function wpinv_increase_discount_usage($code) { |
|
780 | 780 | |
781 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
782 | - $uses = wpinv_get_discount_uses( $id ); |
|
781 | + $id = wpinv_get_discount_id_by_code($code); |
|
782 | + $uses = wpinv_get_discount_uses($id); |
|
783 | 783 | |
784 | - if ( $uses ) { |
|
784 | + if ($uses) { |
|
785 | 785 | $uses++; |
786 | 786 | } else { |
787 | 787 | $uses = 1; |
788 | 788 | } |
789 | 789 | |
790 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
790 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
791 | 791 | |
792 | - do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code ); |
|
792 | + do_action('wpinv_discount_increase_use_count', $uses, $id, $code); |
|
793 | 793 | |
794 | 794 | return $uses; |
795 | 795 | |
796 | 796 | } |
797 | 797 | |
798 | -function wpinv_decrease_discount_usage( $code ) { |
|
798 | +function wpinv_decrease_discount_usage($code) { |
|
799 | 799 | |
800 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
801 | - $uses = wpinv_get_discount_uses( $id ); |
|
800 | + $id = wpinv_get_discount_id_by_code($code); |
|
801 | + $uses = wpinv_get_discount_uses($id); |
|
802 | 802 | |
803 | - if ( $uses ) { |
|
803 | + if ($uses) { |
|
804 | 804 | $uses--; |
805 | 805 | } |
806 | 806 | |
807 | - if ( $uses < 0 ) { |
|
807 | + if ($uses < 0) { |
|
808 | 808 | $uses = 0; |
809 | 809 | } |
810 | 810 | |
811 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
811 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
812 | 812 | |
813 | - do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code ); |
|
813 | + do_action('wpinv_discount_decrease_use_count', $uses, $id, $code); |
|
814 | 814 | |
815 | 815 | return $uses; |
816 | 816 | |
817 | 817 | } |
818 | 818 | |
819 | -function wpinv_format_discount_rate( $type, $amount ) { |
|
820 | - if ( $type == 'flat' ) { |
|
821 | - return wpinv_price( wpinv_format_amount( $amount ) ); |
|
819 | +function wpinv_format_discount_rate($type, $amount) { |
|
820 | + if ($type == 'flat') { |
|
821 | + return wpinv_price(wpinv_format_amount($amount)); |
|
822 | 822 | } else { |
823 | 823 | return $amount . '%'; |
824 | 824 | } |
825 | 825 | } |
826 | 826 | |
827 | -function wpinv_set_cart_discount( $code = '' ) { |
|
828 | - if ( wpinv_multiple_discounts_allowed() ) { |
|
827 | +function wpinv_set_cart_discount($code = '') { |
|
828 | + if (wpinv_multiple_discounts_allowed()) { |
|
829 | 829 | // Get all active cart discounts |
830 | 830 | $discounts = wpinv_get_cart_discounts(); |
831 | 831 | } else { |
832 | 832 | $discounts = false; // Only one discount allowed per purchase, so override any existing |
833 | 833 | } |
834 | 834 | |
835 | - if ( $discounts ) { |
|
836 | - $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) ); |
|
837 | - if( false !== $key ) { |
|
838 | - unset( $discounts[ $key ] ); // Can't set the same discount more than once |
|
835 | + if ($discounts) { |
|
836 | + $key = array_search(strtolower($code), array_map('strtolower', $discounts)); |
|
837 | + if (false !== $key) { |
|
838 | + unset($discounts[$key]); // Can't set the same discount more than once |
|
839 | 839 | } |
840 | 840 | $discounts[] = $code; |
841 | 841 | } else { |
842 | 842 | $discounts = array(); |
843 | 843 | $discounts[] = $code; |
844 | 844 | } |
845 | - $discounts = array_values( $discounts ); |
|
845 | + $discounts = array_values($discounts); |
|
846 | 846 | |
847 | 847 | $data = wpinv_get_checkout_session(); |
848 | - if ( empty( $data ) ) { |
|
848 | + if (empty($data)) { |
|
849 | 849 | $data = array(); |
850 | 850 | } else { |
851 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
852 | - $payment_meta['user_info']['discount'] = implode( ',', $discounts ); |
|
853 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
851 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
852 | + $payment_meta['user_info']['discount'] = implode(',', $discounts); |
|
853 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
854 | 854 | } |
855 | 855 | } |
856 | 856 | $data['cart_discounts'] = $discounts; |
857 | 857 | |
858 | - wpinv_set_checkout_session( $data ); |
|
858 | + wpinv_set_checkout_session($data); |
|
859 | 859 | |
860 | 860 | return $discounts; |
861 | 861 | } |
862 | 862 | |
863 | -function wpinv_unset_cart_discount( $code = '' ) { |
|
863 | +function wpinv_unset_cart_discount($code = '') { |
|
864 | 864 | $discounts = wpinv_get_cart_discounts(); |
865 | 865 | |
866 | - if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
867 | - $key = array_search( $code, $discounts ); |
|
868 | - unset( $discounts[ $key ] ); |
|
866 | + if ($code && !empty($discounts) && in_array($code, $discounts)) { |
|
867 | + $key = array_search($code, $discounts); |
|
868 | + unset($discounts[$key]); |
|
869 | 869 | |
870 | 870 | $data = wpinv_get_checkout_session(); |
871 | 871 | $data['cart_discounts'] = $discounts; |
872 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
873 | - $payment_meta['user_info']['discount'] = !empty( $discounts ) ? implode( ',', $discounts ) : ''; |
|
874 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
872 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
873 | + $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : ''; |
|
874 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
875 | 875 | } |
876 | 876 | |
877 | - wpinv_set_checkout_session( $data ); |
|
877 | + wpinv_set_checkout_session($data); |
|
878 | 878 | } |
879 | 879 | |
880 | 880 | return $discounts; |
@@ -883,27 +883,27 @@ discard block |
||
883 | 883 | function wpinv_unset_all_cart_discounts() { |
884 | 884 | $data = wpinv_get_checkout_session(); |
885 | 885 | |
886 | - if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) { |
|
887 | - unset( $data['cart_discounts'] ); |
|
886 | + if (!empty($data) && isset($data['cart_discounts'])) { |
|
887 | + unset($data['cart_discounts']); |
|
888 | 888 | |
889 | - wpinv_set_checkout_session( $data ); |
|
889 | + wpinv_set_checkout_session($data); |
|
890 | 890 | return true; |
891 | 891 | } |
892 | 892 | |
893 | 893 | return false; |
894 | 894 | } |
895 | 895 | |
896 | -function wpinv_get_cart_discounts( $items = array() ) { |
|
896 | +function wpinv_get_cart_discounts($items = array()) { |
|
897 | 897 | $session = wpinv_get_checkout_session(); |
898 | 898 | |
899 | - $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false; |
|
899 | + $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false; |
|
900 | 900 | return $discounts; |
901 | 901 | } |
902 | 902 | |
903 | -function wpinv_cart_has_discounts( $items = array() ) { |
|
903 | +function wpinv_cart_has_discounts($items = array()) { |
|
904 | 904 | $ret = false; |
905 | 905 | |
906 | - if ( wpinv_get_cart_discounts( $items ) ) { |
|
906 | + if (wpinv_get_cart_discounts($items)) { |
|
907 | 907 | $ret = true; |
908 | 908 | } |
909 | 909 | |
@@ -914,131 +914,131 @@ discard block |
||
914 | 914 | } |
915 | 915 | */ |
916 | 916 | |
917 | - return apply_filters( 'wpinv_cart_has_discounts', $ret ); |
|
917 | + return apply_filters('wpinv_cart_has_discounts', $ret); |
|
918 | 918 | } |
919 | 919 | |
920 | -function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) { |
|
920 | +function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) { |
|
921 | 921 | $amount = 0.00; |
922 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
922 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
923 | 923 | |
924 | - if ( $items ) { |
|
925 | - $discounts = wp_list_pluck( $items, 'discount' ); |
|
924 | + if ($items) { |
|
925 | + $discounts = wp_list_pluck($items, 'discount'); |
|
926 | 926 | |
927 | - if ( is_array( $discounts ) ) { |
|
928 | - $discounts = array_map( 'floatval', $discounts ); |
|
929 | - $amount = array_sum( $discounts ); |
|
927 | + if (is_array($discounts)) { |
|
928 | + $discounts = array_map('floatval', $discounts); |
|
929 | + $amount = array_sum($discounts); |
|
930 | 930 | } |
931 | 931 | } |
932 | 932 | |
933 | - return apply_filters( 'wpinv_get_cart_discounted_amount', $amount ); |
|
933 | + return apply_filters('wpinv_get_cart_discounted_amount', $amount); |
|
934 | 934 | } |
935 | 935 | |
936 | -function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) { |
|
937 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
936 | +function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) { |
|
937 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
938 | 938 | |
939 | - if ( empty( $discount ) || empty( $items ) ) { |
|
939 | + if (empty($discount) || empty($items)) { |
|
940 | 940 | return 0; |
941 | 941 | } |
942 | 942 | |
943 | 943 | $amount = 0; |
944 | 944 | |
945 | - foreach ( $items as $item ) { |
|
946 | - $amount += wpinv_get_cart_item_discount_amount( $item, $discount ); |
|
945 | + foreach ($items as $item) { |
|
946 | + $amount += wpinv_get_cart_item_discount_amount($item, $discount); |
|
947 | 947 | } |
948 | 948 | |
949 | - $amount = wpinv_round_amount( $amount ); |
|
949 | + $amount = wpinv_round_amount($amount); |
|
950 | 950 | |
951 | 951 | return $amount; |
952 | 952 | } |
953 | 953 | |
954 | -function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) { |
|
954 | +function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) { |
|
955 | 955 | global $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
956 | 956 | |
957 | 957 | $amount = 0; |
958 | 958 | |
959 | - if ( empty( $item ) || empty( $item['id'] ) ) { |
|
959 | + if (empty($item) || empty($item['id'])) { |
|
960 | 960 | return $amount; |
961 | 961 | } |
962 | 962 | |
963 | - if ( empty( $item['quantity'] ) ) { |
|
963 | + if (empty($item['quantity'])) { |
|
964 | 964 | return $amount; |
965 | 965 | } |
966 | 966 | |
967 | - if ( empty( $item['options'] ) ) { |
|
967 | + if (empty($item['options'])) { |
|
968 | 968 | $item['options'] = array(); |
969 | 969 | } |
970 | 970 | |
971 | - $price = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] ); |
|
971 | + $price = wpinv_get_cart_item_price($item['id'], $item, $item['options']); |
|
972 | 972 | $discounted_price = $price; |
973 | 973 | |
974 | 974 | $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount; |
975 | - if ( empty( $discounts ) ) { |
|
975 | + if (empty($discounts)) { |
|
976 | 976 | return $amount; |
977 | 977 | } |
978 | 978 | |
979 | - if ( $discounts ) { |
|
980 | - if ( is_array( $discounts ) ) { |
|
981 | - $discounts = array_values( $discounts ); |
|
979 | + if ($discounts) { |
|
980 | + if (is_array($discounts)) { |
|
981 | + $discounts = array_values($discounts); |
|
982 | 982 | } else { |
983 | - $discounts = explode( ',', $discounts ); |
|
983 | + $discounts = explode(',', $discounts); |
|
984 | 984 | } |
985 | 985 | } |
986 | 986 | |
987 | - if( $discounts ) { |
|
988 | - foreach ( $discounts as $discount ) { |
|
989 | - $code_id = wpinv_get_discount_id_by_code( $discount ); |
|
987 | + if ($discounts) { |
|
988 | + foreach ($discounts as $discount) { |
|
989 | + $code_id = wpinv_get_discount_id_by_code($discount); |
|
990 | 990 | |
991 | 991 | // Check discount exists |
992 | - if( ! $code_id ) { |
|
992 | + if (!$code_id) { |
|
993 | 993 | continue; |
994 | 994 | } |
995 | 995 | |
996 | - $reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
997 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
996 | + $reqs = wpinv_get_discount_item_reqs($code_id); |
|
997 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
998 | 998 | |
999 | 999 | // Make sure requirements are set and that this discount shouldn't apply to the whole cart |
1000 | - if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) { |
|
1001 | - foreach ( $reqs as $item_id ) { |
|
1002 | - if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) { |
|
1003 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
1000 | + if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) { |
|
1001 | + foreach ($reqs as $item_id) { |
|
1002 | + if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) { |
|
1003 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
1004 | 1004 | } |
1005 | 1005 | } |
1006 | 1006 | } else { |
1007 | 1007 | // This is a global cart discount |
1008 | - if ( !in_array( $item['id'], $excluded_items ) ) { |
|
1009 | - if ( 'flat' === wpinv_get_discount_type( $code_id ) ) { |
|
1008 | + if (!in_array($item['id'], $excluded_items)) { |
|
1009 | + if ('flat' === wpinv_get_discount_type($code_id)) { |
|
1010 | 1010 | $items_subtotal = 0.00; |
1011 | 1011 | $cart_items = wpinv_get_cart_contents(); |
1012 | 1012 | |
1013 | - foreach ( $cart_items as $cart_item ) { |
|
1014 | - if ( ! in_array( $cart_item['id'], $excluded_items ) ) { |
|
1015 | - $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array(); |
|
1016 | - $item_price = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options ); |
|
1013 | + foreach ($cart_items as $cart_item) { |
|
1014 | + if (!in_array($cart_item['id'], $excluded_items)) { |
|
1015 | + $options = !empty($cart_item['options']) ? $cart_item['options'] : array(); |
|
1016 | + $item_price = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options); |
|
1017 | 1017 | $items_subtotal += $item_price * $cart_item['quantity']; |
1018 | 1018 | } |
1019 | 1019 | } |
1020 | 1020 | |
1021 | - $subtotal_percent = ( ( $price * $item['quantity'] ) / $items_subtotal ); |
|
1022 | - $code_amount = wpinv_get_discount_amount( $code_id ); |
|
1021 | + $subtotal_percent = (($price * $item['quantity']) / $items_subtotal); |
|
1022 | + $code_amount = wpinv_get_discount_amount($code_id); |
|
1023 | 1023 | $discounted_amount = $code_amount * $subtotal_percent; |
1024 | 1024 | $discounted_price -= $discounted_amount; |
1025 | 1025 | |
1026 | - $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() ); |
|
1026 | + $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter()); |
|
1027 | 1027 | |
1028 | - if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) { |
|
1028 | + if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) { |
|
1029 | 1029 | $adjustment = $code_amount - $wpinv_flat_discount_total; |
1030 | 1030 | $discounted_price -= $adjustment; |
1031 | 1031 | } |
1032 | 1032 | } else { |
1033 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
1033 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
1034 | 1034 | } |
1035 | 1035 | } |
1036 | 1036 | } |
1037 | 1037 | } |
1038 | 1038 | |
1039 | - $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) ); |
|
1039 | + $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price)); |
|
1040 | 1040 | |
1041 | - if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) { |
|
1041 | + if ('flat' !== wpinv_get_discount_type($code_id)) { |
|
1042 | 1042 | $amount = $amount * $item['quantity']; |
1043 | 1043 | } |
1044 | 1044 | } |
@@ -1046,59 +1046,59 @@ discard block |
||
1046 | 1046 | return $amount; |
1047 | 1047 | } |
1048 | 1048 | |
1049 | -function wpinv_cart_discounts_html( $items = array() ) { |
|
1050 | - echo wpinv_get_cart_discounts_html( $items ); |
|
1049 | +function wpinv_cart_discounts_html($items = array()) { |
|
1050 | + echo wpinv_get_cart_discounts_html($items); |
|
1051 | 1051 | } |
1052 | 1052 | |
1053 | -function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) { |
|
1053 | +function wpinv_get_cart_discounts_html($items = array(), $discounts = false) { |
|
1054 | 1054 | global $wpi_cart_columns; |
1055 | 1055 | |
1056 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
1056 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
1057 | 1057 | |
1058 | - if ( !$discounts ) { |
|
1059 | - $discounts = wpinv_get_cart_discounts( $items ); |
|
1058 | + if (!$discounts) { |
|
1059 | + $discounts = wpinv_get_cart_discounts($items); |
|
1060 | 1060 | } |
1061 | 1061 | |
1062 | - if ( !$discounts ) { |
|
1062 | + if (!$discounts) { |
|
1063 | 1063 | return; |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - $discounts = is_array( $discounts ) ? $discounts : array( $discounts ); |
|
1066 | + $discounts = is_array($discounts) ? $discounts : array($discounts); |
|
1067 | 1067 | |
1068 | 1068 | $html = ''; |
1069 | 1069 | |
1070 | - foreach ( $discounts as $discount ) { |
|
1071 | - $discount_id = wpinv_get_discount_id_by_code( $discount ); |
|
1072 | - $discount_value = wpinv_get_discount_amount( $discount_id ); |
|
1073 | - $rate = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value ); |
|
1074 | - $amount = wpinv_get_cart_items_discount_amount( $items, $discount ); |
|
1075 | - $remove_btn = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
1070 | + foreach ($discounts as $discount) { |
|
1071 | + $discount_id = wpinv_get_discount_id_by_code($discount); |
|
1072 | + $discount_value = wpinv_get_discount_amount($discount_id); |
|
1073 | + $rate = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value); |
|
1074 | + $amount = wpinv_get_cart_items_discount_amount($items, $discount); |
|
1075 | + $remove_btn = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
1076 | 1076 | |
1077 | 1077 | $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">'; |
1078 | 1078 | ob_start(); |
1079 | - do_action( 'wpinv_checkout_table_discount_first', $items ); |
|
1079 | + do_action('wpinv_checkout_table_discount_first', $items); |
|
1080 | 1080 | $html .= ob_get_clean(); |
1081 | - $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>'; |
|
1081 | + $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>'; |
|
1082 | 1082 | ob_start(); |
1083 | - do_action( 'wpinv_checkout_table_discount_last', $items ); |
|
1083 | + do_action('wpinv_checkout_table_discount_last', $items); |
|
1084 | 1084 | $html .= ob_get_clean(); |
1085 | 1085 | $html .= '</tr>'; |
1086 | 1086 | } |
1087 | 1087 | |
1088 | - return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate ); |
|
1088 | + return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate); |
|
1089 | 1089 | } |
1090 | 1090 | |
1091 | -function wpinv_display_cart_discount( $formatted = false, $echo = false ) { |
|
1091 | +function wpinv_display_cart_discount($formatted = false, $echo = false) { |
|
1092 | 1092 | $discounts = wpinv_get_cart_discounts(); |
1093 | 1093 | |
1094 | - if ( empty( $discounts ) ) { |
|
1094 | + if (empty($discounts)) { |
|
1095 | 1095 | return false; |
1096 | 1096 | } |
1097 | 1097 | |
1098 | - $discount_id = wpinv_get_discount_id_by_code( $discounts[0] ); |
|
1099 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) ); |
|
1098 | + $discount_id = wpinv_get_discount_id_by_code($discounts[0]); |
|
1099 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id)); |
|
1100 | 1100 | |
1101 | - if ( $echo ) { |
|
1101 | + if ($echo) { |
|
1102 | 1102 | echo $amount; |
1103 | 1103 | } |
1104 | 1104 | |
@@ -1106,135 +1106,135 @@ discard block |
||
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | function wpinv_remove_cart_discount() { |
1109 | - if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) { |
|
1109 | + if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) { |
|
1110 | 1110 | return; |
1111 | 1111 | } |
1112 | 1112 | |
1113 | - do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
1113 | + do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id'])); |
|
1114 | 1114 | |
1115 | - wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) ); |
|
1115 | + wpinv_unset_cart_discount(urldecode($_GET['discount_code'])); |
|
1116 | 1116 | |
1117 | - do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
1117 | + do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id'])); |
|
1118 | 1118 | |
1119 | - wp_redirect( wpinv_get_checkout_uri() ); wpinv_die(); |
|
1119 | + wp_redirect(wpinv_get_checkout_uri()); wpinv_die(); |
|
1120 | 1120 | } |
1121 | -add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' ); |
|
1121 | +add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount'); |
|
1122 | 1122 | |
1123 | -function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) { |
|
1123 | +function wpinv_maybe_remove_cart_discount($cart_key = 0) { |
|
1124 | 1124 | $discounts = wpinv_get_cart_discounts(); |
1125 | 1125 | |
1126 | - if ( !$discounts ) { |
|
1126 | + if (!$discounts) { |
|
1127 | 1127 | return; |
1128 | 1128 | } |
1129 | 1129 | |
1130 | - foreach ( $discounts as $discount ) { |
|
1131 | - if ( !wpinv_is_discount_valid( $discount ) ) { |
|
1132 | - wpinv_unset_cart_discount( $discount ); |
|
1130 | + foreach ($discounts as $discount) { |
|
1131 | + if (!wpinv_is_discount_valid($discount)) { |
|
1132 | + wpinv_unset_cart_discount($discount); |
|
1133 | 1133 | } |
1134 | 1134 | } |
1135 | 1135 | } |
1136 | -add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' ); |
|
1136 | +add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount'); |
|
1137 | 1137 | |
1138 | 1138 | function wpinv_multiple_discounts_allowed() { |
1139 | - $ret = wpinv_get_option( 'allow_multiple_discounts', false ); |
|
1140 | - return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret ); |
|
1139 | + $ret = wpinv_get_option('allow_multiple_discounts', false); |
|
1140 | + return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret); |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | 1143 | function wpinv_listen_for_cart_discount() { |
1144 | 1144 | global $wpi_session; |
1145 | 1145 | |
1146 | - if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) { |
|
1146 | + if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) { |
|
1147 | 1147 | return; |
1148 | 1148 | } |
1149 | 1149 | |
1150 | - $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] ); |
|
1150 | + $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']); |
|
1151 | 1151 | |
1152 | - $wpi_session->set( 'preset_discount', $code ); |
|
1152 | + $wpi_session->set('preset_discount', $code); |
|
1153 | 1153 | } |
1154 | 1154 | //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 ); |
1155 | 1155 | |
1156 | 1156 | function wpinv_apply_preset_discount() { |
1157 | 1157 | global $wpi_session; |
1158 | 1158 | |
1159 | - $code = $wpi_session->get( 'preset_discount' ); |
|
1159 | + $code = $wpi_session->get('preset_discount'); |
|
1160 | 1160 | |
1161 | - if ( !$code ) { |
|
1161 | + if (!$code) { |
|
1162 | 1162 | return; |
1163 | 1163 | } |
1164 | 1164 | |
1165 | - if ( !wpinv_is_discount_valid( $code, '', false ) ) { |
|
1165 | + if (!wpinv_is_discount_valid($code, '', false)) { |
|
1166 | 1166 | return; |
1167 | 1167 | } |
1168 | 1168 | |
1169 | - $code = apply_filters( 'wpinv_apply_preset_discount', $code ); |
|
1169 | + $code = apply_filters('wpinv_apply_preset_discount', $code); |
|
1170 | 1170 | |
1171 | - wpinv_set_cart_discount( $code ); |
|
1171 | + wpinv_set_cart_discount($code); |
|
1172 | 1172 | |
1173 | - $wpi_session->set( 'preset_discount', null ); |
|
1173 | + $wpi_session->set('preset_discount', null); |
|
1174 | 1174 | } |
1175 | 1175 | //add_action( 'init', 'wpinv_apply_preset_discount', 999 ); |
1176 | 1176 | |
1177 | -function wpinv_get_discount_label( $code, $echo = true ) { |
|
1178 | - $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) ); |
|
1179 | - $label = apply_filters( 'wpinv_get_discount_label', $label, $code ); |
|
1177 | +function wpinv_get_discount_label($code, $echo = true) { |
|
1178 | + $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : '')); |
|
1179 | + $label = apply_filters('wpinv_get_discount_label', $label, $code); |
|
1180 | 1180 | |
1181 | - if ( $echo ) { |
|
1181 | + if ($echo) { |
|
1182 | 1182 | echo $label; |
1183 | 1183 | } else { |
1184 | 1184 | return $label; |
1185 | 1185 | } |
1186 | 1186 | } |
1187 | 1187 | |
1188 | -function wpinv_cart_discount_label( $code, $rate, $echo = true ) { |
|
1189 | - $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code ); |
|
1190 | - $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate ); |
|
1188 | +function wpinv_cart_discount_label($code, $rate, $echo = true) { |
|
1189 | + $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code); |
|
1190 | + $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate); |
|
1191 | 1191 | |
1192 | - if ( $echo ) { |
|
1192 | + if ($echo) { |
|
1193 | 1193 | echo $label; |
1194 | 1194 | } else { |
1195 | 1195 | return $label; |
1196 | 1196 | } |
1197 | 1197 | } |
1198 | 1198 | |
1199 | -function wpinv_check_delete_discount( $check, $post, $force_delete ) { |
|
1200 | - if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) { |
|
1199 | +function wpinv_check_delete_discount($check, $post, $force_delete) { |
|
1200 | + if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) { |
|
1201 | 1201 | return true; |
1202 | 1202 | } |
1203 | 1203 | |
1204 | 1204 | return $check; |
1205 | 1205 | } |
1206 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 ); |
|
1206 | +add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3); |
|
1207 | 1207 | |
1208 | 1208 | function wpinv_checkout_form_validate_discounts() { |
1209 | 1209 | global $wpi_checkout_id; |
1210 | 1210 | |
1211 | 1211 | $discounts = wpinv_get_cart_discounts(); |
1212 | 1212 | |
1213 | - if ( !empty( $discounts ) ) { |
|
1213 | + if (!empty($discounts)) { |
|
1214 | 1214 | $invalid = false; |
1215 | 1215 | |
1216 | - foreach ( $discounts as $key => $code ) { |
|
1217 | - if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) { |
|
1216 | + foreach ($discounts as $key => $code) { |
|
1217 | + if (!wpinv_is_discount_valid($code, (int)wpinv_get_user_id($wpi_checkout_id))) { |
|
1218 | 1218 | $invalid = true; |
1219 | 1219 | |
1220 | - wpinv_unset_cart_discount( $code ); |
|
1220 | + wpinv_unset_cart_discount($code); |
|
1221 | 1221 | } |
1222 | 1222 | } |
1223 | 1223 | |
1224 | - if ( $invalid ) { |
|
1224 | + if ($invalid) { |
|
1225 | 1225 | $errors = wpinv_get_errors(); |
1226 | - $error = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
1227 | - $error .= __( 'The discount has been removed from cart.', 'invoicing' ); |
|
1228 | - wpinv_set_error( 'wpinv-discount-error', $error ); |
|
1226 | + $error = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
1227 | + $error .= __('The discount has been removed from cart.', 'invoicing'); |
|
1228 | + wpinv_set_error('wpinv-discount-error', $error); |
|
1229 | 1229 | |
1230 | - wpinv_recalculate_tax( true ); |
|
1230 | + wpinv_recalculate_tax(true); |
|
1231 | 1231 | } |
1232 | 1232 | } |
1233 | 1233 | } |
1234 | -add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 ); |
|
1234 | +add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10); |
|
1235 | 1235 | |
1236 | 1236 | function wpinv_discount_amount() { |
1237 | 1237 | $output = 0.00; |
1238 | 1238 | |
1239 | - return apply_filters( 'wpinv_discount_amount', $output ); |
|
1239 | + return apply_filters('wpinv_discount_amount', $output); |
|
1240 | 1240 | } |
1241 | 1241 | \ No newline at end of file |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_action( 'wpinv_manual_cc_form', '__return_false' ); |
|
5 | +add_action('wpinv_manual_cc_form', '__return_false'); |
|
6 | 6 | |
7 | -function wpinv_process_manual_payment( $purchase_data ) { |
|
8 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
9 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
7 | +function wpinv_process_manual_payment($purchase_data) { |
|
8 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
9 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | /* |
@@ -41,22 +41,22 @@ discard block |
||
41 | 41 | ); |
42 | 42 | |
43 | 43 | // Record the pending payment |
44 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
44 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
45 | 45 | |
46 | - if ( !empty( $invoice ) ) { |
|
47 | - wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() ); |
|
48 | - wpinv_update_payment_status( $invoice, 'publish' ); |
|
46 | + if (!empty($invoice)) { |
|
47 | + wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key()); |
|
48 | + wpinv_update_payment_status($invoice, 'publish'); |
|
49 | 49 | |
50 | 50 | // Empty the shopping cart |
51 | 51 | wpinv_empty_cart(); |
52 | 52 | |
53 | - do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data ); |
|
53 | + do_action('wpinv_send_to_success_page', $invoice->ID, $payment_data); |
|
54 | 54 | |
55 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
55 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
56 | 56 | } else { |
57 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
57 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
58 | 58 | // If errors are present, send the user back to the purchase page so they can be corrected |
59 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
59 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
60 | 60 | } |
61 | 61 | } |
62 | -add_action( 'wpinv_gateway_manual', 'wpinv_process_manual_payment' ); |
|
63 | 62 | \ No newline at end of file |
63 | +add_action('wpinv_gateway_manual', 'wpinv_process_manual_payment'); |
|
64 | 64 | \ No newline at end of file |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_action( 'wpinv_worldpay_cc_form', '__return_false' ); |
|
5 | +add_action('wpinv_worldpay_cc_form', '__return_false'); |
|
6 | 6 | |
7 | -function wpinv_process_worldpay_payment( $purchase_data ) { |
|
8 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
9 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
7 | +function wpinv_process_worldpay_payment($purchase_data) { |
|
8 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
9 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | // Collect payment data |
@@ -24,132 +24,132 @@ discard block |
||
24 | 24 | ); |
25 | 25 | |
26 | 26 | // Record the pending payment |
27 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
27 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
28 | 28 | |
29 | - if ( !empty( $invoice ) ) { |
|
29 | + if (!empty($invoice)) { |
|
30 | 30 | $quantities_enabled = wpinv_item_quantities_enabled(); |
31 | 31 | |
32 | - $instId = wpinv_get_option( 'worldpay_instId', false ); |
|
32 | + $instId = wpinv_get_option('worldpay_instId', false); |
|
33 | 33 | $cartId = $invoice->get_number(); |
34 | - $testMode = wpinv_is_test_mode( 'worldpay' ) ? 100 : 0; |
|
34 | + $testMode = wpinv_is_test_mode('worldpay') ? 100 : 0; |
|
35 | 35 | $name = $invoice->get_user_full_name(); |
36 | - $address = wp_strip_all_tags( $invoice->get_address(), true ); |
|
36 | + $address = wp_strip_all_tags($invoice->get_address(), true); |
|
37 | 37 | $postcode = $invoice->zip; |
38 | 38 | $tel = $invoice->phone; |
39 | 39 | $email = $invoice->get_email(); |
40 | 40 | $country = $invoice->country; |
41 | - $amount = wpinv_sanitize_amount( $invoice->get_total() ); |
|
41 | + $amount = wpinv_sanitize_amount($invoice->get_total()); |
|
42 | 42 | $currency = wpinv_get_currency(); |
43 | 43 | |
44 | 44 | $items = array(); |
45 | - foreach ( $invoice->get_cart_details() as $item ) { |
|
45 | + foreach ($invoice->get_cart_details() as $item) { |
|
46 | 46 | $item_desc = $item['name']; |
47 | - $quantity = !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
48 | - $item_desc .= ' (' . ( $quantities_enabled ? $quantity . 'x ' : '' ) . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')'; |
|
47 | + $quantity = !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
48 | + $item_desc .= ' (' . ($quantities_enabled ? $quantity . 'x ' : '') . wpinv_price(wpinv_format_amount($item['item_price'])) . ')'; |
|
49 | 49 | |
50 | 50 | $items[] = $item_desc; |
51 | 51 | } |
52 | 52 | |
53 | - $desc = implode( ', ', $items ); |
|
54 | - if ( wpinv_use_taxes() && $invoice->get_tax() > 0 ) { |
|
55 | - $desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) ); |
|
53 | + $desc = implode(', ', $items); |
|
54 | + if (wpinv_use_taxes() && $invoice->get_tax() > 0) { |
|
55 | + $desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true)); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | $extra_params = array(); |
59 | 59 | $extra_params['MC_description'] = $desc; |
60 | - $extra_params['MC_callback'] = wpinv_get_ipn_url( 'worldpay' ); |
|
60 | + $extra_params['MC_callback'] = wpinv_get_ipn_url('worldpay'); |
|
61 | 61 | $extra_params['MC_key'] = $invoice->get_key(); |
62 | 62 | $extra_params['MC_invoice_id'] = $invoice->ID; |
63 | 63 | $extra_params['address1'] = $address; |
64 | 64 | $extra_params['town'] = $invoice->city; |
65 | 65 | $extra_params['region'] = $invoice->state; |
66 | - $extra_params['amountString'] = $invoice->get_total( true ); |
|
67 | - $extra_params['countryString'] = wpinv_country_name( $invoice->country ); |
|
66 | + $extra_params['amountString'] = $invoice->get_total(true); |
|
67 | + $extra_params['countryString'] = wpinv_country_name($invoice->country); |
|
68 | 68 | $extra_params['compName'] = $invoice->company; |
69 | 69 | |
70 | - $extra_params = apply_filters( 'wpinv_worldpay_form_extra_parameters', $extra_params, $invoice ); |
|
70 | + $extra_params = apply_filters('wpinv_worldpay_form_extra_parameters', $extra_params, $invoice); |
|
71 | 71 | |
72 | - $redirect_text = __( 'Redirecting to Worldpay site, click on button if not redirected.', 'invoicing' ); |
|
73 | - $redirect_text = apply_filters( 'wpinv_worldpay_redirect_text', $redirect_text, $invoice ); |
|
72 | + $redirect_text = __('Redirecting to Worldpay site, click on button if not redirected.', 'invoicing'); |
|
73 | + $redirect_text = apply_filters('wpinv_worldpay_redirect_text', $redirect_text, $invoice); |
|
74 | 74 | |
75 | 75 | // Empty the shopping cart |
76 | 76 | wpinv_empty_cart(); |
77 | 77 | ?> |
78 | 78 | <div class="wpi-worldpay-form" style="padding:20px;font-family:arial,sans-serif;text-align:center;color:#555"> |
79 | -<?php do_action( 'wpinv_worldpay_form_before', $invoice ); ?> |
|
80 | -<h3><?php echo $redirect_text ;?></h3> |
|
79 | +<?php do_action('wpinv_worldpay_form_before', $invoice); ?> |
|
80 | +<h3><?php echo $redirect_text; ?></h3> |
|
81 | 81 | <form action="<?php echo wpinv_get_worldpay_redirect(); ?>" name="wpi_worldpay_form" method="POST"> |
82 | - <input type="hidden" value="<?php echo $amount;?>" name="amount"> |
|
83 | - <input type="hidden" value="<?php echo esc_attr( $cartId );?>" name="cartId"> |
|
84 | - <input type="hidden" value="<?php echo $currency;?>" name="currency"> |
|
85 | - <input type="hidden" value="<?php echo $instId;?>" name="instId"> |
|
86 | - <input type="hidden" value="<?php echo $testMode;?>" name="testMode"> |
|
87 | - <input type="hidden" value="<?php echo esc_attr( $name );?>" name="name"> |
|
88 | - <input type="hidden" value="<?php echo esc_attr( $address );?>" name="address"> |
|
89 | - <input type="hidden" value="<?php echo esc_attr( $postcode );?>" name="postcode"> |
|
90 | - <input type="hidden" value="<?php echo esc_attr( $tel );?>" name="tel"> |
|
91 | - <input type="hidden" value="<?php echo esc_attr( $email );?>" name="email"> |
|
92 | - <input type="hidden" value="<?php echo esc_attr( $country );?>" name="country"> |
|
93 | - <input type="hidden" value="<?php echo esc_attr( $desc );?>" name="desc"> |
|
94 | - <?php foreach ( $extra_params as $param => $value ) { ?> |
|
95 | - <?php if ( !empty( $value !== false ) ) { ?> |
|
96 | - <input type="hidden" value="<?php echo esc_attr( $value );?>" name="<?php echo esc_attr( $param );?>"> |
|
82 | + <input type="hidden" value="<?php echo $amount; ?>" name="amount"> |
|
83 | + <input type="hidden" value="<?php echo esc_attr($cartId); ?>" name="cartId"> |
|
84 | + <input type="hidden" value="<?php echo $currency; ?>" name="currency"> |
|
85 | + <input type="hidden" value="<?php echo $instId; ?>" name="instId"> |
|
86 | + <input type="hidden" value="<?php echo $testMode; ?>" name="testMode"> |
|
87 | + <input type="hidden" value="<?php echo esc_attr($name); ?>" name="name"> |
|
88 | + <input type="hidden" value="<?php echo esc_attr($address); ?>" name="address"> |
|
89 | + <input type="hidden" value="<?php echo esc_attr($postcode); ?>" name="postcode"> |
|
90 | + <input type="hidden" value="<?php echo esc_attr($tel); ?>" name="tel"> |
|
91 | + <input type="hidden" value="<?php echo esc_attr($email); ?>" name="email"> |
|
92 | + <input type="hidden" value="<?php echo esc_attr($country); ?>" name="country"> |
|
93 | + <input type="hidden" value="<?php echo esc_attr($desc); ?>" name="desc"> |
|
94 | + <?php foreach ($extra_params as $param => $value) { ?> |
|
95 | + <?php if (!empty($value !== false)) { ?> |
|
96 | + <input type="hidden" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($param); ?>"> |
|
97 | 97 | <?php } ?> |
98 | 98 | <?php } ?> |
99 | - <?php do_action( 'wpinv_worldpay_form_parameters', $invoice ); ?> |
|
100 | - <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e( 'Pay by Debit/Credit Card (WorldPay)', 'invoicing' ) ;?>"> |
|
99 | + <?php do_action('wpinv_worldpay_form_parameters', $invoice); ?> |
|
100 | + <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e('Pay by Debit/Credit Card (WorldPay)', 'invoicing'); ?>"> |
|
101 | 101 | </form> |
102 | 102 | <script type="text/javascript">document.wpi_worldpay_form.submit();</script> |
103 | -<?php do_action( 'wpinv_worldpay_form_after', $invoice ); ?> |
|
103 | +<?php do_action('wpinv_worldpay_form_after', $invoice); ?> |
|
104 | 104 | </div> |
105 | 105 | <?php |
106 | 106 | } else { |
107 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
107 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
108 | 108 | // If errors are present, send the user back to the purchase page so they can be corrected |
109 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
109 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
110 | 110 | } |
111 | 111 | } |
112 | -add_action( 'wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment' ); |
|
112 | +add_action('wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment'); |
|
113 | 113 | |
114 | 114 | function wpinv_get_worldpay_redirect() { |
115 | - $redirect = wpinv_is_test_mode( 'worldpay' ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
115 | + $redirect = wpinv_is_test_mode('worldpay') ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
116 | 116 | |
117 | - return apply_filters( 'wpinv_worldpay_redirect', $redirect ); |
|
117 | + return apply_filters('wpinv_worldpay_redirect', $redirect); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | function wpinv_process_worldpay_ipn() { |
121 | - $request = wpinv_get_post_data( 'post' ); |
|
121 | + $request = wpinv_get_post_data('post'); |
|
122 | 122 | |
123 | - if ( !empty( $request['cartId'] ) && !empty( $request['transStatus'] ) && !empty( $request['installation'] ) && isset( $request['testMode'] ) && isset( $request['MC_invoice_id'] ) && isset( $request['MC_key'] ) ) { |
|
123 | + if (!empty($request['cartId']) && !empty($request['transStatus']) && !empty($request['installation']) && isset($request['testMode']) && isset($request['MC_invoice_id']) && isset($request['MC_key'])) { |
|
124 | 124 | $invoice_id = $request['MC_invoice_id']; |
125 | 125 | |
126 | - if ( $invoice_id == wpinv_get_invoice_id_by_key( $request['MC_key'] ) && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
127 | - if ( $request['transStatus'] == 'Y' ) { |
|
128 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
129 | - wpinv_set_payment_transaction_id( $invoice_id, $request['transId'] ); |
|
130 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Worldpay Transaction ID: %s', 'invoicing' ), $request['transId'] ) ); |
|
126 | + if ($invoice_id == wpinv_get_invoice_id_by_key($request['MC_key']) && $invoice = wpinv_get_invoice($invoice_id)) { |
|
127 | + if ($request['transStatus'] == 'Y') { |
|
128 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
129 | + wpinv_set_payment_transaction_id($invoice_id, $request['transId']); |
|
130 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Worldpay Transaction ID: %s', 'invoicing'), $request['transId'])); |
|
131 | 131 | return; |
132 | - } else if ( $request['transStatus'] == 'C' ) { |
|
133 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
134 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing' ) ); |
|
132 | + } else if ($request['transStatus'] == 'C') { |
|
133 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
134 | + wpinv_insert_payment_note($invoice_id, __('Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing')); |
|
135 | 135 | |
136 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing' ), json_encode( $request ) ), $invoice_id ); |
|
136 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing'), json_encode($request)), $invoice_id); |
|
137 | 137 | return; |
138 | 138 | } |
139 | 139 | } |
140 | 140 | } |
141 | 141 | return; |
142 | 142 | } |
143 | -add_action( 'wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn' ); |
|
143 | +add_action('wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn'); |
|
144 | 144 | |
145 | 145 | function wpinv_is_worldpay_valid_for_use() { |
146 | - return in_array( wpinv_get_currency(), apply_filters( 'wpinv_worldpay_supported_currencies', array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ))); |
|
146 | + return in_array(wpinv_get_currency(), apply_filters('wpinv_worldpay_supported_currencies', array('AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR'))); |
|
147 | 147 | } |
148 | 148 | |
149 | -function wpinv_check_worldpay_currency_support( $gateway_list ) { |
|
150 | - if ( isset( $gateway_list['worldpay'] ) && ! wpinv_is_worldpay_valid_for_use() ) { |
|
151 | - unset( $gateway_list['worldpay'] ); |
|
149 | +function wpinv_check_worldpay_currency_support($gateway_list) { |
|
150 | + if (isset($gateway_list['worldpay']) && !wpinv_is_worldpay_valid_for_use()) { |
|
151 | + unset($gateway_list['worldpay']); |
|
152 | 152 | } |
153 | 153 | return $gateway_list; |
154 | 154 | } |
155 | -add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1 ); |
|
156 | 155 | \ No newline at end of file |
156 | +add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1); |
|
157 | 157 | \ No newline at end of file |