@@ -7,7 +7,7 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 |
@@ -7,7 +7,7 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 |
@@ -7,7 +7,7 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 |
@@ -7,7 +7,7 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 |
@@ -7,7 +7,7 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 |
@@ -13,128 +13,128 @@ |
||
13 | 13 | class GetPaid_Payment_Forms { |
14 | 14 | |
15 | 15 | /** |
16 | - * Class constructor |
|
17 | - * |
|
18 | - */ |
|
19 | - public function __construct() { |
|
20 | - |
|
21 | - // Update a payment form's revenue whenever an invoice is paid for or refunded. |
|
22 | - add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | - add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
24 | - |
|
25 | - // Sync form amount whenever invoice statuses change. |
|
26 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
29 | - |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Increments a form's revenue whenever there is a payment. |
|
34 | - * |
|
35 | - * @param WPInv_Invoice $invoice |
|
36 | - */ |
|
37 | - public function increment_form_revenue( $invoice ) { |
|
38 | - |
|
39 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | - if ( $form->get_id() ) { |
|
41 | - $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
42 | - $form->save(); |
|
43 | - } |
|
44 | - |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Decreases form revenue whenever invoice payment changes. |
|
49 | - * |
|
50 | - * @param WPInv_Invoice $invoice |
|
51 | - */ |
|
52 | - public function decrease_form_revenue( $invoice ) { |
|
53 | - |
|
54 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | - if ( $form->get_id() ) { |
|
56 | - $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
57 | - $form->save(); |
|
58 | - } |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Updates a form's failed amount. |
|
64 | - * |
|
65 | - * @param WPInv_Invoice $invoice |
|
66 | - * @param string $from |
|
67 | - * @param string $to |
|
68 | - */ |
|
69 | - public function update_form_failed_amount( $invoice, $from, $to ) { |
|
70 | - |
|
71 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | - if ( $form->get_id() ) { |
|
73 | - return; |
|
74 | - } |
|
75 | - |
|
76 | - if ( 'wpi-failed' == $from ) { |
|
77 | - $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
78 | - $form->save(); |
|
79 | - } |
|
80 | - |
|
81 | - if ( 'wpi-failed' == $to ) { |
|
82 | - $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
83 | - $form->save(); |
|
84 | - } |
|
85 | - |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Updates a form's refunded amount. |
|
90 | - * |
|
91 | - * @param WPInv_Invoice $invoice |
|
92 | - * @param string $from |
|
93 | - * @param string $to |
|
94 | - */ |
|
95 | - public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
96 | - |
|
97 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | - if ( $form->get_id() ) { |
|
99 | - return; |
|
100 | - } |
|
101 | - |
|
102 | - if ( 'wpi-refunded' == $from ) { |
|
103 | - $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
104 | - $form->save(); |
|
105 | - } |
|
106 | - |
|
107 | - if ( 'wpi-refunded' == $to ) { |
|
108 | - $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
109 | - $form->save(); |
|
110 | - } |
|
111 | - |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Updates a form's cancelled amount. |
|
116 | - * |
|
117 | - * @param WPInv_Invoice $invoice |
|
118 | - * @param string $from |
|
119 | - * @param string $to |
|
120 | - */ |
|
121 | - public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
122 | - |
|
123 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | - if ( $form->get_id() ) { |
|
125 | - return; |
|
126 | - } |
|
127 | - |
|
128 | - if ( 'wpi-cancelled' == $from ) { |
|
129 | - $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
130 | - $form->save(); |
|
131 | - } |
|
132 | - |
|
133 | - if ( 'wpi-cancelled' == $to ) { |
|
134 | - $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
135 | - $form->save(); |
|
136 | - } |
|
137 | - |
|
138 | - } |
|
16 | + * Class constructor |
|
17 | + * |
|
18 | + */ |
|
19 | + public function __construct() { |
|
20 | + |
|
21 | + // Update a payment form's revenue whenever an invoice is paid for or refunded. |
|
22 | + add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | + add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
24 | + |
|
25 | + // Sync form amount whenever invoice statuses change. |
|
26 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
29 | + |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Increments a form's revenue whenever there is a payment. |
|
34 | + * |
|
35 | + * @param WPInv_Invoice $invoice |
|
36 | + */ |
|
37 | + public function increment_form_revenue( $invoice ) { |
|
38 | + |
|
39 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | + if ( $form->get_id() ) { |
|
41 | + $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
42 | + $form->save(); |
|
43 | + } |
|
44 | + |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Decreases form revenue whenever invoice payment changes. |
|
49 | + * |
|
50 | + * @param WPInv_Invoice $invoice |
|
51 | + */ |
|
52 | + public function decrease_form_revenue( $invoice ) { |
|
53 | + |
|
54 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | + if ( $form->get_id() ) { |
|
56 | + $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
57 | + $form->save(); |
|
58 | + } |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Updates a form's failed amount. |
|
64 | + * |
|
65 | + * @param WPInv_Invoice $invoice |
|
66 | + * @param string $from |
|
67 | + * @param string $to |
|
68 | + */ |
|
69 | + public function update_form_failed_amount( $invoice, $from, $to ) { |
|
70 | + |
|
71 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | + if ( $form->get_id() ) { |
|
73 | + return; |
|
74 | + } |
|
75 | + |
|
76 | + if ( 'wpi-failed' == $from ) { |
|
77 | + $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
78 | + $form->save(); |
|
79 | + } |
|
80 | + |
|
81 | + if ( 'wpi-failed' == $to ) { |
|
82 | + $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
83 | + $form->save(); |
|
84 | + } |
|
85 | + |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Updates a form's refunded amount. |
|
90 | + * |
|
91 | + * @param WPInv_Invoice $invoice |
|
92 | + * @param string $from |
|
93 | + * @param string $to |
|
94 | + */ |
|
95 | + public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
96 | + |
|
97 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | + if ( $form->get_id() ) { |
|
99 | + return; |
|
100 | + } |
|
101 | + |
|
102 | + if ( 'wpi-refunded' == $from ) { |
|
103 | + $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
104 | + $form->save(); |
|
105 | + } |
|
106 | + |
|
107 | + if ( 'wpi-refunded' == $to ) { |
|
108 | + $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
109 | + $form->save(); |
|
110 | + } |
|
111 | + |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Updates a form's cancelled amount. |
|
116 | + * |
|
117 | + * @param WPInv_Invoice $invoice |
|
118 | + * @param string $from |
|
119 | + * @param string $to |
|
120 | + */ |
|
121 | + public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
122 | + |
|
123 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | + if ( $form->get_id() ) { |
|
125 | + return; |
|
126 | + } |
|
127 | + |
|
128 | + if ( 'wpi-cancelled' == $from ) { |
|
129 | + $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
130 | + $form->save(); |
|
131 | + } |
|
132 | + |
|
133 | + if ( 'wpi-cancelled' == $to ) { |
|
134 | + $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
135 | + $form->save(); |
|
136 | + } |
|
137 | + |
|
138 | + } |
|
139 | 139 | |
140 | 140 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment forms controller class |
@@ -19,13 +19,13 @@ discard block |
||
19 | 19 | public function __construct() { |
20 | 20 | |
21 | 21 | // Update a payment form's revenue whenever an invoice is paid for or refunded. |
22 | - add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | - add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
22 | + add_action('getpaid_invoice_payment_status_changed', array($this, 'increment_form_revenue')); |
|
23 | + add_action('getpaid_invoice_payment_status_reversed', array($this, 'decrease_form_revenue')); |
|
24 | 24 | |
25 | 25 | // Sync form amount whenever invoice statuses change. |
26 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
26 | + add_action('getpaid_invoice_status_changed', array($this, 'update_form_failed_amount'), 10, 3); |
|
27 | + add_action('getpaid_invoice_status_changed', array($this, 'update_form_refunded_amount'), 10, 3); |
|
28 | + add_action('getpaid_invoice_status_changed', array($this, 'update_form_cancelled_amount'), 10, 3); |
|
29 | 29 | |
30 | 30 | } |
31 | 31 | |
@@ -34,11 +34,11 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @param WPInv_Invoice $invoice |
36 | 36 | */ |
37 | - public function increment_form_revenue( $invoice ) { |
|
37 | + public function increment_form_revenue($invoice) { |
|
38 | 38 | |
39 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | - if ( $form->get_id() ) { |
|
41 | - $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
39 | + $form = new GetPaid_Payment_Form($invoice->get_payment_form()); |
|
40 | + if ($form->get_id()) { |
|
41 | + $form->set_earned($form->get_earned() + $invoice->get_total()); |
|
42 | 42 | $form->save(); |
43 | 43 | } |
44 | 44 | |
@@ -49,11 +49,11 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @param WPInv_Invoice $invoice |
51 | 51 | */ |
52 | - public function decrease_form_revenue( $invoice ) { |
|
52 | + public function decrease_form_revenue($invoice) { |
|
53 | 53 | |
54 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | - if ( $form->get_id() ) { |
|
56 | - $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
54 | + $form = new GetPaid_Payment_Form($invoice->get_payment_form()); |
|
55 | + if ($form->get_id()) { |
|
56 | + $form->set_earned($form->get_earned() - $invoice->get_total()); |
|
57 | 57 | $form->save(); |
58 | 58 | } |
59 | 59 | |
@@ -66,20 +66,20 @@ discard block |
||
66 | 66 | * @param string $from |
67 | 67 | * @param string $to |
68 | 68 | */ |
69 | - public function update_form_failed_amount( $invoice, $from, $to ) { |
|
69 | + public function update_form_failed_amount($invoice, $from, $to) { |
|
70 | 70 | |
71 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | - if ( $form->get_id() ) { |
|
71 | + $form = new GetPaid_Payment_Form($invoice->get_payment_form()); |
|
72 | + if ($form->get_id()) { |
|
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
76 | - if ( 'wpi-failed' == $from ) { |
|
77 | - $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
76 | + if ('wpi-failed' == $from) { |
|
77 | + $form->set_failed($form->get_failed() - $invoice->get_total()); |
|
78 | 78 | $form->save(); |
79 | 79 | } |
80 | 80 | |
81 | - if ( 'wpi-failed' == $to ) { |
|
82 | - $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
81 | + if ('wpi-failed' == $to) { |
|
82 | + $form->set_failed($form->get_failed() + $invoice->get_total()); |
|
83 | 83 | $form->save(); |
84 | 84 | } |
85 | 85 | |
@@ -92,20 +92,20 @@ discard block |
||
92 | 92 | * @param string $from |
93 | 93 | * @param string $to |
94 | 94 | */ |
95 | - public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
95 | + public function update_form_refunded_amount($invoice, $from, $to) { |
|
96 | 96 | |
97 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | - if ( $form->get_id() ) { |
|
97 | + $form = new GetPaid_Payment_Form($invoice->get_payment_form()); |
|
98 | + if ($form->get_id()) { |
|
99 | 99 | return; |
100 | 100 | } |
101 | 101 | |
102 | - if ( 'wpi-refunded' == $from ) { |
|
103 | - $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
102 | + if ('wpi-refunded' == $from) { |
|
103 | + $form->set_refunded($form->get_refunded() - $invoice->get_total()); |
|
104 | 104 | $form->save(); |
105 | 105 | } |
106 | 106 | |
107 | - if ( 'wpi-refunded' == $to ) { |
|
108 | - $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
107 | + if ('wpi-refunded' == $to) { |
|
108 | + $form->set_refunded($form->get_refunded() + $invoice->get_total()); |
|
109 | 109 | $form->save(); |
110 | 110 | } |
111 | 111 | |
@@ -118,20 +118,20 @@ discard block |
||
118 | 118 | * @param string $from |
119 | 119 | * @param string $to |
120 | 120 | */ |
121 | - public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
121 | + public function update_form_cancelled_amount($invoice, $from, $to) { |
|
122 | 122 | |
123 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | - if ( $form->get_id() ) { |
|
123 | + $form = new GetPaid_Payment_Form($invoice->get_payment_form()); |
|
124 | + if ($form->get_id()) { |
|
125 | 125 | return; |
126 | 126 | } |
127 | 127 | |
128 | - if ( 'wpi-cancelled' == $from ) { |
|
129 | - $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
128 | + if ('wpi-cancelled' == $from) { |
|
129 | + $form->set_cancelled($form->get_cancelled() - $invoice->get_total()); |
|
130 | 130 | $form->save(); |
131 | 131 | } |
132 | 132 | |
133 | - if ( 'wpi-cancelled' == $to ) { |
|
134 | - $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
133 | + if ('wpi-cancelled' == $to) { |
|
134 | + $form->set_cancelled($form->get_cancelled() + $invoice->get_total()); |
|
135 | 135 | $form->save(); |
136 | 136 | } |
137 | 137 |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; // Exit if accessed directly |
|
10 | + exit; // Exit if accessed directly |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | class GetPaid_Meta_Box_Payment_Form { |
17 | 17 | |
18 | 18 | /** |
19 | - * Output the metabox. |
|
20 | - * |
|
21 | - * @param WP_Post $post |
|
22 | - */ |
|
19 | + * Output the metabox. |
|
20 | + * |
|
21 | + * @param WP_Post $post |
|
22 | + */ |
|
23 | 23 | public static function output( $post ) { |
24 | 24 | ?> |
25 | 25 | <div id="wpinv-form-builder" class="bsui"> |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | - * Save meta box data. |
|
90 | - * |
|
91 | - * @param int $post_id |
|
92 | - */ |
|
93 | - public static function save( $post_id ) { |
|
89 | + * Save meta box data. |
|
90 | + * |
|
91 | + * @param int $post_id |
|
92 | + */ |
|
93 | + public static function save( $post_id ) { |
|
94 | 94 | |
95 | 95 | // Prepare the form. |
96 | 96 | $form = new GetPaid_Payment_Form( $post_id ); |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | - * Converts an array fo form items to objects. |
|
125 | - * |
|
126 | - * @param array $items |
|
127 | - */ |
|
128 | - public static function item_to_objects( $items ) { |
|
124 | + * Converts an array fo form items to objects. |
|
125 | + * |
|
126 | + * @param array $items |
|
127 | + */ |
|
128 | + public static function item_to_objects( $items ) { |
|
129 | 129 | |
130 | 130 | $objects = array(); |
131 | 131 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if (!defined('ABSPATH')) { |
|
10 | 10 | exit; // Exit if accessed directly |
11 | 11 | } |
12 | 12 | |
@@ -20,14 +20,14 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @param WP_Post $post |
22 | 22 | */ |
23 | - public static function output( $post ) { |
|
23 | + public static function output($post) { |
|
24 | 24 | ?> |
25 | 25 | <div id="wpinv-form-builder" class="bsui"> |
26 | 26 | <div class="row"> |
27 | 27 | <div class="col-sm-4"> |
28 | 28 | |
29 | 29 | <!-- Builder tabs --> |
30 | - <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e( 'Go Back', 'invoicing' ); ?></button> |
|
30 | + <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e('Go Back', 'invoicing'); ?></button> |
|
31 | 31 | |
32 | 32 | <!-- Builder tab content --> |
33 | 33 | <div class="mt-4"> |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | <!-- Available builder elements --> |
36 | 36 | <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'"> |
37 | 37 | <div class="wpinv-form-builder-add-field-types"> |
38 | - <small class='form-text text-muted'><?php _e( 'Add an element by dragging it to the payment form.', 'invoicing' ); ?></small> |
|
38 | + <small class='form-text text-muted'><?php _e('Add an element by dragging it to the payment form.', 'invoicing'); ?></small> |
|
39 | 39 | <draggable class="section mt-2" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable"> |
40 | 40 | <li v-for="element in elements" class= "wpinv-payment-form-left-fields-field" @click.prevent="addField(element)" :class="{ 'd-none': element.defaults.premade }"> |
41 | 41 | <button class="button btn text-dark"> |
@@ -50,18 +50,18 @@ discard block |
||
50 | 50 | <!-- Edit an element --> |
51 | 51 | <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='edit_item'" style="font-size: 14px;"> |
52 | 52 | <div class="wpinv-form-builder-edit-field-wrapper"> |
53 | - <?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?> |
|
54 | - <?php do_action( 'getpaid_payment_form_edit_element_template', $post ); ?> |
|
53 | + <?php do_action('wpinv_payment_form_edit_element_template', 'active_form_element', $post); ?> |
|
54 | + <?php do_action('getpaid_payment_form_edit_element_template', $post); ?> |
|
55 | 55 | <div class='form-group'> |
56 | - <label :for="active_form_element.id + '_grid_width'"><?php esc_html_e( 'Width', 'invoicing' ) ?></label> |
|
56 | + <label :for="active_form_element.id + '_grid_width'"><?php esc_html_e('Width', 'invoicing') ?></label> |
|
57 | 57 | <select class='form-control custom-select' :id="active_form_element.id + '_grid_width'" v-model='gridWidth'> |
58 | - <option value='full'><?php esc_html_e( 'Full Width', 'invoicing' ); ?></option> |
|
59 | - <option value='half'><?php esc_html_e( 'Half Width', 'invoicing' ); ?></option> |
|
60 | - <option value='third'><?php esc_html_e( '1/3 Width', 'invoicing' ); ?></option> |
|
58 | + <option value='full'><?php esc_html_e('Full Width', 'invoicing'); ?></option> |
|
59 | + <option value='half'><?php esc_html_e('Half Width', 'invoicing'); ?></option> |
|
60 | + <option value='third'><?php esc_html_e('1/3 Width', 'invoicing'); ?></option> |
|
61 | 61 | </select> |
62 | 62 | </div> |
63 | 63 | <div> |
64 | - <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e( 'Delete Element', 'invoicing' ); ?></button> |
|
64 | + <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e('Delete Element', 'invoicing'); ?></button> |
|
65 | 65 | </div> |
66 | 66 | </div> |
67 | 67 | </div> |
@@ -70,15 +70,15 @@ discard block |
||
70 | 70 | |
71 | 71 | </div> |
72 | 72 | <div class="col-sm-8 border-left"> |
73 | - <small class='form-text text-muted' v-if='form_elements.length'><?php _e( 'Click on any element to edit or delete it.', 'invoicing' ); ?></small> |
|
74 | - <p class='form-text text-muted' v-if='! form_elements.length'><?php _e( 'This form is empty. Add new elements by dragging them from the right.', 'invoicing' ); ?></p> |
|
73 | + <small class='form-text text-muted' v-if='form_elements.length'><?php _e('Click on any element to edit or delete it.', 'invoicing'); ?></small> |
|
74 | + <p class='form-text text-muted' v-if='! form_elements.length'><?php _e('This form is empty. Add new elements by dragging them from the right.', 'invoicing'); ?></p> |
|
75 | 75 | |
76 | 76 | <div class="container-fluid"> |
77 | 77 | <draggable class="section row" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 14px;"> |
78 | 78 | <div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="[{ active: active_form_element==form_element && active_tab=='edit_item' }, form_element.type, grid_class( form_element ) ]" @click="active_tab = 'edit_item'; active_form_element = form_element"> |
79 | 79 | <div class="wpinv-form-builder-element-preview-inner"> |
80 | 80 | <div class="wpinv-payment-form-field-preview-overlay"></div> |
81 | - <?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?> |
|
81 | + <?php do_action('wpinv_payment_form_render_element_template', 'form_element', $post); ?> |
|
82 | 82 | </div> |
83 | 83 | </div> |
84 | 84 | </draggable> |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | </div> |
93 | 93 | <?php |
94 | 94 | |
95 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
95 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -100,33 +100,33 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @param int $post_id |
102 | 102 | */ |
103 | - public static function save( $post_id ) { |
|
103 | + public static function save($post_id) { |
|
104 | 104 | |
105 | 105 | // Prepare the form. |
106 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
106 | + $form = new GetPaid_Payment_Form($post_id); |
|
107 | 107 | |
108 | 108 | // Fetch form items. |
109 | - $form_items = json_decode( wp_unslash( $_POST['wpinv_form_items'] ), true ); |
|
109 | + $form_items = json_decode(wp_unslash($_POST['wpinv_form_items']), true); |
|
110 | 110 | |
111 | 111 | // Ensure that we have an array... |
112 | - if ( empty( $form_items ) ) { |
|
112 | + if (empty($form_items)) { |
|
113 | 113 | $form_items = array(); |
114 | 114 | } |
115 | 115 | |
116 | 116 | // Add it to the form. |
117 | - $form->set_items( self::item_to_objects( $form_items ) ); |
|
117 | + $form->set_items(self::item_to_objects($form_items)); |
|
118 | 118 | |
119 | 119 | // Save form elements. |
120 | - $form_elements = json_decode( wp_unslash( $_POST['wpinv_form_elements'] ), true ); |
|
121 | - if ( empty( $form_elements ) ) { |
|
120 | + $form_elements = json_decode(wp_unslash($_POST['wpinv_form_elements']), true); |
|
121 | + if (empty($form_elements)) { |
|
122 | 122 | $form_elements = array(); |
123 | 123 | } |
124 | 124 | |
125 | - $form->set_elements( $form_elements ); |
|
125 | + $form->set_elements($form_elements); |
|
126 | 126 | |
127 | 127 | // Persist data to the datastore. |
128 | 128 | $form->save(); |
129 | - do_action( 'getpaid_payment_form_metabox_save', $post_id, $form ); |
|
129 | + do_action('getpaid_payment_form_metabox_save', $post_id, $form); |
|
130 | 130 | |
131 | 131 | } |
132 | 132 | |
@@ -135,14 +135,14 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @param array $items |
137 | 137 | */ |
138 | - public static function item_to_objects( $items ) { |
|
138 | + public static function item_to_objects($items) { |
|
139 | 139 | |
140 | 140 | $objects = array(); |
141 | 141 | |
142 | - foreach ( $items as $item ) { |
|
143 | - $_item = new GetPaid_Form_Item( $item['id'] ); |
|
144 | - $_item->set_allow_quantities( (bool) $item['allow_quantities'] ); |
|
145 | - $_item->set_is_required( (bool) $item['required'] ); |
|
142 | + foreach ($items as $item) { |
|
143 | + $_item = new GetPaid_Form_Item($item['id']); |
|
144 | + $_item->set_allow_quantities((bool) $item['allow_quantities']); |
|
145 | + $_item->set_is_required((bool) $item['required']); |
|
146 | 146 | $objects[] = $_item; |
147 | 147 | } |
148 | 148 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Discount_Details { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the discount. |
@@ -368,34 +368,34 @@ discard block |
||
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
371 | - * Save meta box data. |
|
372 | - * |
|
373 | - * @param int $post_id |
|
374 | - */ |
|
375 | - public static function save( $post_id ) { |
|
371 | + * Save meta box data. |
|
372 | + * |
|
373 | + * @param int $post_id |
|
374 | + */ |
|
375 | + public static function save( $post_id ) { |
|
376 | 376 | |
377 | 377 | // Prepare the discount. |
378 | 378 | $discount = new WPInv_Discount( $post_id ); |
379 | 379 | |
380 | 380 | // Load new data. |
381 | 381 | $discount->set_props( |
382 | - array( |
|
383 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
384 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
385 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
382 | + array( |
|
383 | + 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
384 | + 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
385 | + 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | + 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | + 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
388 | 388 | 'type' => isset( $_POST['wpinv_discount_type'] ) ? $_POST['wpinv_discount_type'] : null, |
389 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
391 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
392 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
393 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
394 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
395 | - ) |
|
389 | + 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | + 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
391 | + 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
392 | + 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
393 | + 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
394 | + 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
395 | + ) |
|
396 | 396 | ); |
397 | 397 | |
398 | - $discount->save(); |
|
399 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
400 | - } |
|
398 | + $discount->save(); |
|
399 | + do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
400 | + } |
|
401 | 401 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,24 +21,24 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the discount. |
27 | - $discount = new WPInv_Discount( $post ); |
|
27 | + $discount = new WPInv_Discount($post); |
|
28 | 28 | |
29 | 29 | // Nonce field. |
30 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
30 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
31 | 31 | |
32 | - do_action( 'wpinv_discount_form_top', $discount ); |
|
32 | + do_action('wpinv_discount_form_top', $discount); |
|
33 | 33 | |
34 | 34 | // Set the currency position. |
35 | 35 | $position = wpinv_currency_position(); |
36 | 36 | |
37 | - if ( $position == 'left_space' ) { |
|
37 | + if ($position == 'left_space') { |
|
38 | 38 | $position = 'left'; |
39 | 39 | } |
40 | 40 | |
41 | - if ( $position == 'right_space' ) { |
|
41 | + if ($position == 'right_space') { |
|
42 | 42 | $position = 'right'; |
43 | 43 | } |
44 | 44 | |
@@ -52,66 +52,66 @@ discard block |
||
52 | 52 | </style> |
53 | 53 | <div class='bsui' style='max-width: 600px;padding-top: 10px;'> |
54 | 54 | |
55 | - <?php do_action( 'wpinv_discount_form_first', $discount ); ?> |
|
55 | + <?php do_action('wpinv_discount_form_first', $discount); ?> |
|
56 | 56 | |
57 | - <?php do_action( 'wpinv_discount_form_before_code', $discount ); ?> |
|
57 | + <?php do_action('wpinv_discount_form_before_code', $discount); ?> |
|
58 | 58 | <div class="form-group row"> |
59 | 59 | <label for="wpinv_discount_code" class="col-sm-3 col-form-label"> |
60 | - <?php _e( 'Discount Code', 'invoicing' );?> |
|
60 | + <?php _e('Discount Code', 'invoicing'); ?> |
|
61 | 61 | </label> |
62 | 62 | <div class="col-sm-8"> |
63 | 63 | <div class="row"> |
64 | 64 | <div class="col-sm-12 form-group"> |
65 | - <input type="text" value="<?php echo esc_attr( $discount->get_code( 'edit' ) ); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" /> |
|
65 | + <input type="text" value="<?php echo esc_attr($discount->get_code('edit')); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" /> |
|
66 | 66 | </div> |
67 | 67 | <div class="col-sm-12"> |
68 | 68 | <?php |
69 | - do_action( 'wpinv_discount_form_before_single_use', $discount ); |
|
69 | + do_action('wpinv_discount_form_before_single_use', $discount); |
|
70 | 70 | |
71 | 71 | echo aui()->input( |
72 | 72 | array( |
73 | 73 | 'id' => 'wpinv_discount_single_use', |
74 | 74 | 'name' => 'wpinv_discount_single_use', |
75 | 75 | 'type' => 'checkbox', |
76 | - 'label' => __( 'Each customer can only use this discount once', 'invoicing' ), |
|
76 | + 'label' => __('Each customer can only use this discount once', 'invoicing'), |
|
77 | 77 | 'value' => '1', |
78 | 78 | 'checked' => $discount->is_single_use(), |
79 | 79 | ) |
80 | 80 | ); |
81 | 81 | |
82 | - do_action( 'wpinv_discount_form_single_use', $discount ); |
|
82 | + do_action('wpinv_discount_form_single_use', $discount); |
|
83 | 83 | ?> |
84 | 84 | </div> |
85 | 85 | <div class="col-sm-12"> |
86 | 86 | <?php |
87 | - do_action( 'wpinv_discount_form_before_recurring', $discount ); |
|
87 | + do_action('wpinv_discount_form_before_recurring', $discount); |
|
88 | 88 | |
89 | 89 | echo aui()->input( |
90 | 90 | array( |
91 | 91 | 'id' => 'wpinv_discount_recurring', |
92 | 92 | 'name' => 'wpinv_discount_recurring', |
93 | 93 | 'type' => 'checkbox', |
94 | - 'label' => __( 'Apply this discount to all recurring payments for subscriptions', 'invoicing' ), |
|
94 | + 'label' => __('Apply this discount to all recurring payments for subscriptions', 'invoicing'), |
|
95 | 95 | 'value' => '1', |
96 | 96 | 'checked' => $discount->is_recurring(), |
97 | 97 | ) |
98 | 98 | ); |
99 | 99 | |
100 | - do_action( 'wpinv_discount_form_recurring', $discount ); |
|
100 | + do_action('wpinv_discount_form_recurring', $discount); |
|
101 | 101 | ?> |
102 | 102 | </div> |
103 | 103 | </div> |
104 | 104 | </div> |
105 | 105 | <div class="col-sm-1 pt-2 pl-0"> |
106 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter a discount code such as 10OFF.', 'invoicing' ); ?>"></span> |
|
106 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter a discount code such as 10OFF.', 'invoicing'); ?>"></span> |
|
107 | 107 | </div> |
108 | 108 | </div> |
109 | - <?php do_action( 'wpinv_discount_form_code', $discount ); ?> |
|
109 | + <?php do_action('wpinv_discount_form_code', $discount); ?> |
|
110 | 110 | |
111 | - <?php do_action( 'wpinv_discount_form_before_type', $discount ); ?> |
|
111 | + <?php do_action('wpinv_discount_form_before_type', $discount); ?> |
|
112 | 112 | <div class="form-group row"> |
113 | 113 | <label for="wpinv_discount_type" class="col-sm-3 col-form-label"> |
114 | - <?php _e( 'Discount Type', 'invoicing' );?> |
|
114 | + <?php _e('Discount Type', 'invoicing'); ?> |
|
115 | 115 | </label> |
116 | 116 | <div class="col-sm-8"> |
117 | 117 | <?php |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | array( |
120 | 120 | 'id' => 'wpinv_discount_type', |
121 | 121 | 'name' => 'wpinv_discount_type', |
122 | - 'label' => __( 'Discount Type', 'invoicing' ), |
|
123 | - 'placeholder' => __( 'Select Discount Type', 'invoicing' ), |
|
124 | - 'value' => $discount->get_type( 'edit' ), |
|
122 | + 'label' => __('Discount Type', 'invoicing'), |
|
123 | + 'placeholder' => __('Select Discount Type', 'invoicing'), |
|
124 | + 'value' => $discount->get_type('edit'), |
|
125 | 125 | 'select2' => true, |
126 | 126 | 'data-allow-clear' => 'false', |
127 | 127 | 'options' => wpinv_get_discount_types() |
@@ -130,19 +130,19 @@ discard block |
||
130 | 130 | ?> |
131 | 131 | </div> |
132 | 132 | <div class="col-sm-1 pt-2 pl-0"> |
133 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Discount type.', 'invoicing' ); ?>"></span> |
|
133 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Discount type.', 'invoicing'); ?>"></span> |
|
134 | 134 | </div> |
135 | 135 | </div> |
136 | - <?php do_action( 'wpinv_discount_form_type', $discount ); ?> |
|
136 | + <?php do_action('wpinv_discount_form_type', $discount); ?> |
|
137 | 137 | |
138 | - <?php do_action( 'wpinv_discount_form_before_amount', $discount ); ?> |
|
139 | - <div class="form-group row <?php echo esc_attr( $discount->get_type( 'edit' ) ); ?>" id="wpinv_discount_amount_wrap"> |
|
138 | + <?php do_action('wpinv_discount_form_before_amount', $discount); ?> |
|
139 | + <div class="form-group row <?php echo esc_attr($discount->get_type('edit')); ?>" id="wpinv_discount_amount_wrap"> |
|
140 | 140 | <label for="wpinv_discount_amount" class="col-sm-3 col-form-label"> |
141 | - <?php _e( 'Discount Amount', 'invoicing' );?> |
|
141 | + <?php _e('Discount Amount', 'invoicing'); ?> |
|
142 | 142 | </label> |
143 | 143 | <div class="col-sm-8"> |
144 | 144 | <div class="input-group input-group-sm"> |
145 | - <?php if( 'left' == $position ) : ?> |
|
145 | + <?php if ('left' == $position) : ?> |
|
146 | 146 | <div class="input-group-prepend left wpinv-if-flat"> |
147 | 147 | <span class="input-group-text"> |
148 | 148 | <?php echo wpinv_currency_symbol(); ?> |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | </div> |
151 | 151 | <?php endif; ?> |
152 | 152 | |
153 | - <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr( $discount->get_amount( 'edit' ) ); ?>" placeholder="0" class="form-control"> |
|
153 | + <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr($discount->get_amount('edit')); ?>" placeholder="0" class="form-control"> |
|
154 | 154 | |
155 | - <?php if( 'right' == $position ) : ?> |
|
155 | + <?php if ('right' == $position) : ?> |
|
156 | 156 | <div class="input-group-prepend left wpinv-if-flat"> |
157 | 157 | <span class="input-group-text"> |
158 | 158 | <?php echo wpinv_currency_symbol(); ?> |
@@ -165,15 +165,15 @@ discard block |
||
165 | 165 | </div> |
166 | 166 | </div> |
167 | 167 | <div class="col-sm-1 pt-2 pl-0"> |
168 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?>"></span> |
|
168 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter the discount value. Ex: 10', 'invoicing'); ?>"></span> |
|
169 | 169 | </div> |
170 | 170 | </div> |
171 | - <?php do_action( 'wpinv_discount_form_amount', $discount ); ?> |
|
171 | + <?php do_action('wpinv_discount_form_amount', $discount); ?> |
|
172 | 172 | |
173 | - <?php do_action( 'wpinv_discount_form_before_items', $discount ); ?> |
|
173 | + <?php do_action('wpinv_discount_form_before_items', $discount); ?> |
|
174 | 174 | <div class="form-group row"> |
175 | 175 | <label for="wpinv_discount_items" class="col-sm-3 col-form-label"> |
176 | - <?php _e( 'Items', 'invoicing' );?> |
|
176 | + <?php _e('Items', 'invoicing'); ?> |
|
177 | 177 | </label> |
178 | 178 | <div class="col-sm-8"> |
179 | 179 | <?php |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | array( |
182 | 182 | 'id' => 'wpinv_discount_items', |
183 | 183 | 'name' => 'wpinv_discount_items[]', |
184 | - 'label' => __( 'Items', 'invoicing' ), |
|
185 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
186 | - 'value' => $discount->get_items( 'edit' ), |
|
184 | + 'label' => __('Items', 'invoicing'), |
|
185 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
186 | + 'value' => $discount->get_items('edit'), |
|
187 | 187 | 'select2' => true, |
188 | 188 | 'multiple' => true, |
189 | 189 | 'data-allow-clear' => 'false', |
@@ -193,15 +193,15 @@ discard block |
||
193 | 193 | ?> |
194 | 194 | </div> |
195 | 195 | <div class="col-sm-1 pt-2 pl-0"> |
196 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing' ); ?>"></span> |
|
196 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing'); ?>"></span> |
|
197 | 197 | </div> |
198 | 198 | </div> |
199 | - <?php do_action( 'wpinv_discount_form_items', $discount ); ?> |
|
199 | + <?php do_action('wpinv_discount_form_items', $discount); ?> |
|
200 | 200 | |
201 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $discount ); ?> |
|
201 | + <?php do_action('wpinv_discount_form_before_excluded_items', $discount); ?> |
|
202 | 202 | <div class="form-group row"> |
203 | 203 | <label for="wpinv_discount_excluded_items" class="col-sm-3 col-form-label"> |
204 | - <?php _e( 'Excluded Items', 'invoicing' );?> |
|
204 | + <?php _e('Excluded Items', 'invoicing'); ?> |
|
205 | 205 | </label> |
206 | 206 | <div class="col-sm-8"> |
207 | 207 | <?php |
@@ -209,9 +209,9 @@ discard block |
||
209 | 209 | array( |
210 | 210 | 'id' => 'wpinv_discount_excluded_items', |
211 | 211 | 'name' => 'wpinv_discount_excluded_items[]', |
212 | - 'label' => __( 'Excluded Items', 'invoicing' ), |
|
213 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
214 | - 'value' => $discount->get_excluded_items( 'edit' ), |
|
212 | + 'label' => __('Excluded Items', 'invoicing'), |
|
213 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
214 | + 'value' => $discount->get_excluded_items('edit'), |
|
215 | 215 | 'select2' => true, |
216 | 216 | 'multiple' => true, |
217 | 217 | 'data-allow-clear' => 'false', |
@@ -221,15 +221,15 @@ discard block |
||
221 | 221 | ?> |
222 | 222 | </div> |
223 | 223 | <div class="col-sm-1 pt-2 pl-0"> |
224 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select all the items that are not allowed to use this discount.', 'invoicing' ); ?>"></span> |
|
224 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select all the items that are not allowed to use this discount.', 'invoicing'); ?>"></span> |
|
225 | 225 | </div> |
226 | 226 | </div> |
227 | - <?php do_action( 'wpinv_discount_form_excluded_items', $discount ); ?> |
|
227 | + <?php do_action('wpinv_discount_form_excluded_items', $discount); ?> |
|
228 | 228 | |
229 | - <?php do_action( 'wpinv_discount_form_before_start', $discount ); ?> |
|
229 | + <?php do_action('wpinv_discount_form_before_start', $discount); ?> |
|
230 | 230 | <div class="form-group row"> |
231 | 231 | <label for="wpinv_discount_start" class="col-sm-3 col-form-label"> |
232 | - <?php _e( 'Start Date', 'invoicing' );?> |
|
232 | + <?php _e('Start Date', 'invoicing'); ?> |
|
233 | 233 | </label> |
234 | 234 | <div class="col-sm-8"> |
235 | 235 | <?php |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | 'type' => 'datepicker', |
239 | 239 | 'id' => 'wpinv_discount_start', |
240 | 240 | 'name' => 'wpinv_discount_start', |
241 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
241 | + 'label' => __('Start Date', 'invoicing'), |
|
242 | 242 | 'placeholder' => 'YYYY-MM-DD 00:00', |
243 | 243 | 'class' => 'form-control-sm', |
244 | - 'value' => $discount->get_start_date( 'edit' ), |
|
244 | + 'value' => $discount->get_start_date('edit'), |
|
245 | 245 | 'extra_attributes' => array( |
246 | 246 | 'data-enable-time' => 'true', |
247 | 247 | 'data-time_24hr' => 'true', |
@@ -252,15 +252,15 @@ discard block |
||
252 | 252 | ?> |
253 | 253 | </div> |
254 | 254 | <div class="col-sm-1 pt-2 pl-0"> |
255 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?>"></span> |
|
255 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?>"></span> |
|
256 | 256 | </div> |
257 | 257 | </div> |
258 | - <?php do_action( 'wpinv_discount_form_start', $discount ); ?> |
|
258 | + <?php do_action('wpinv_discount_form_start', $discount); ?> |
|
259 | 259 | |
260 | - <?php do_action( 'wpinv_discount_form_before_expiration', $discount ); ?> |
|
260 | + <?php do_action('wpinv_discount_form_before_expiration', $discount); ?> |
|
261 | 261 | <div class="form-group row"> |
262 | 262 | <label for="wpinv_discount_expiration" class="col-sm-3 col-form-label"> |
263 | - <?php _e( 'Expiration Date', 'invoicing' );?> |
|
263 | + <?php _e('Expiration Date', 'invoicing'); ?> |
|
264 | 264 | </label> |
265 | 265 | <div class="col-sm-8"> |
266 | 266 | <?php |
@@ -269,10 +269,10 @@ discard block |
||
269 | 269 | 'type' => 'datepicker', |
270 | 270 | 'id' => 'wpinv_discount_expiration', |
271 | 271 | 'name' => 'wpinv_discount_expiration', |
272 | - 'label' => __( 'Expiration Date', 'invoicing' ), |
|
272 | + 'label' => __('Expiration Date', 'invoicing'), |
|
273 | 273 | 'placeholder' => 'YYYY-MM-DD 00:00', |
274 | 274 | 'class' => 'form-control-sm', |
275 | - 'value' => $discount->get_end_date( 'edit' ), |
|
275 | + 'value' => $discount->get_end_date('edit'), |
|
276 | 276 | 'extra_attributes' => array( |
277 | 277 | 'data-enable-time' => 'true', |
278 | 278 | 'data-time_24hr' => 'true', |
@@ -285,27 +285,27 @@ discard block |
||
285 | 285 | ?> |
286 | 286 | </div> |
287 | 287 | <div class="col-sm-1 pt-2 pl-0"> |
288 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the date after which the discount will expire.', 'invoicing' ); ?>"></span> |
|
288 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the date after which the discount will expire.', 'invoicing'); ?>"></span> |
|
289 | 289 | </div> |
290 | 290 | </div> |
291 | - <?php do_action( 'wpinv_discount_form_expiration', $discount ); ?> |
|
291 | + <?php do_action('wpinv_discount_form_expiration', $discount); ?> |
|
292 | 292 | |
293 | - <?php do_action( 'wpinv_discount_form_before_min_total', $discount ); ?> |
|
293 | + <?php do_action('wpinv_discount_form_before_min_total', $discount); ?> |
|
294 | 294 | <div class="form-group row"> |
295 | 295 | <label for="wpinv_discount_min_total" class="col-sm-3 col-form-label"> |
296 | - <?php _e( 'Minimum Amount', 'invoicing' );?> |
|
296 | + <?php _e('Minimum Amount', 'invoicing'); ?> |
|
297 | 297 | </label> |
298 | 298 | <div class="col-sm-8"> |
299 | 299 | <div class="input-group input-group-sm"> |
300 | - <?php if( 'left' == $position ) : ?> |
|
300 | + <?php if ('left' == $position) : ?> |
|
301 | 301 | <div class="input-group-prepend"> |
302 | 302 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
303 | 303 | </div> |
304 | 304 | <?php endif; ?> |
305 | 305 | |
306 | - <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr( $discount->get_minimum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No minimum', 'invoicing' ); ?>" class="form-control"> |
|
306 | + <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr($discount->get_minimum_total('edit')); ?>" placeholder="<?php esc_attr_e('No minimum', 'invoicing'); ?>" class="form-control"> |
|
307 | 307 | |
308 | - <?php if( 'left' != $position ) : ?> |
|
308 | + <?php if ('left' != $position) : ?> |
|
309 | 309 | <div class="input-group-append"> |
310 | 310 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
311 | 311 | </div> |
@@ -313,27 +313,27 @@ discard block |
||
313 | 313 | </div> |
314 | 314 | </div> |
315 | 315 | <div class="col-sm-1 pt-2 pl-0"> |
316 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing' ); ?>"></span> |
|
316 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing'); ?>"></span> |
|
317 | 317 | </div> |
318 | 318 | </div> |
319 | - <?php do_action( 'wpinv_discount_form_min_total', $discount ); ?> |
|
319 | + <?php do_action('wpinv_discount_form_min_total', $discount); ?> |
|
320 | 320 | |
321 | - <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?> |
|
321 | + <?php do_action('wpinv_discount_form_before_max_total', $discount); ?> |
|
322 | 322 | <div class="form-group row"> |
323 | 323 | <label for="wpinv_discount_max_total" class="col-sm-3 col-form-label"> |
324 | - <?php _e( 'Maximum Amount', 'invoicing' );?> |
|
324 | + <?php _e('Maximum Amount', 'invoicing'); ?> |
|
325 | 325 | </label> |
326 | 326 | <div class="col-sm-8"> |
327 | 327 | <div class="input-group input-group-sm"> |
328 | - <?php if( 'left' == $position ) : ?> |
|
328 | + <?php if ('left' == $position) : ?> |
|
329 | 329 | <div class="input-group-prepend"> |
330 | 330 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
331 | 331 | </div> |
332 | 332 | <?php endif; ?> |
333 | 333 | |
334 | - <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr( $discount->get_maximum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No maximum', 'invoicing' ); ?>" class="form-control"> |
|
334 | + <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr($discount->get_maximum_total('edit')); ?>" placeholder="<?php esc_attr_e('No maximum', 'invoicing'); ?>" class="form-control"> |
|
335 | 335 | |
336 | - <?php if( 'left' != $position ) : ?> |
|
336 | + <?php if ('left' != $position) : ?> |
|
337 | 337 | <div class="input-group-append"> |
338 | 338 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
339 | 339 | </div> |
@@ -341,30 +341,30 @@ discard block |
||
341 | 341 | </div> |
342 | 342 | </div> |
343 | 343 | <div class="col-sm-1 pt-2 pl-0"> |
344 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing' ); ?>"></span> |
|
344 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing'); ?>"></span> |
|
345 | 345 | </div> |
346 | 346 | </div> |
347 | - <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?> |
|
347 | + <?php do_action('wpinv_discount_form_before_max_total', $discount); ?> |
|
348 | 348 | |
349 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $discount ); ?> |
|
349 | + <?php do_action('wpinv_discount_form_before_max_uses', $discount); ?> |
|
350 | 350 | <div class="form-group row"> |
351 | 351 | <label for="wpinv_discount_max_uses" class="col-sm-3 col-form-label"> |
352 | - <?php _e( 'Maximum Uses', 'invoicing' );?> |
|
352 | + <?php _e('Maximum Uses', 'invoicing'); ?> |
|
353 | 353 | </label> |
354 | 354 | <div class="col-sm-8"> |
355 | - <input type="text" value="<?php echo esc_attr( $discount->get_max_uses( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'Unlimited', 'invoicing' ); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" /> |
|
355 | + <input type="text" value="<?php echo esc_attr($discount->get_max_uses('edit')); ?>" placeholder="<?php esc_attr_e('Unlimited', 'invoicing'); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" /> |
|
356 | 356 | </div> |
357 | 357 | <div class="col-sm-1 pt-2 pl-0"> |
358 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum number of times that this discount code can be used.', 'invoicing' ); ?>"></span> |
|
358 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum number of times that this discount code can be used.', 'invoicing'); ?>"></span> |
|
359 | 359 | </div> |
360 | 360 | </div> |
361 | - <?php do_action( 'wpinv_discount_form_max_uses', $discount ); ?> |
|
361 | + <?php do_action('wpinv_discount_form_max_uses', $discount); ?> |
|
362 | 362 | |
363 | - <?php do_action( 'wpinv_discount_form_last', $discount ); ?> |
|
363 | + <?php do_action('wpinv_discount_form_last', $discount); ?> |
|
364 | 364 | |
365 | 365 | </div> |
366 | 366 | <?php |
367 | - do_action( 'wpinv_discount_form_bottom', $post ); |
|
367 | + do_action('wpinv_discount_form_bottom', $post); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -372,30 +372,30 @@ discard block |
||
372 | 372 | * |
373 | 373 | * @param int $post_id |
374 | 374 | */ |
375 | - public static function save( $post_id ) { |
|
375 | + public static function save($post_id) { |
|
376 | 376 | |
377 | 377 | // Prepare the discount. |
378 | - $discount = new WPInv_Discount( $post_id ); |
|
378 | + $discount = new WPInv_Discount($post_id); |
|
379 | 379 | |
380 | 380 | // Load new data. |
381 | 381 | $discount->set_props( |
382 | 382 | array( |
383 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
384 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
385 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
388 | - 'type' => isset( $_POST['wpinv_discount_type'] ) ? $_POST['wpinv_discount_type'] : null, |
|
389 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
391 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
392 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
393 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
394 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
383 | + 'code' => isset($_POST['wpinv_discount_code']) ? $_POST['wpinv_discount_code'] : null, |
|
384 | + 'amount' => isset($_POST['wpinv_discount_amount']) ? $_POST['wpinv_discount_amount'] : null, |
|
385 | + 'start' => isset($_POST['wpinv_discount_start']) ? wpinv_clean($_POST['wpinv_discount_start']) : null, |
|
386 | + 'expiration' => isset($_POST['wpinv_discount_expiration']) ? wpinv_clean($_POST['wpinv_discount_expiration']) : null, |
|
387 | + 'is_single_use' => isset($_POST['wpinv_discount_single_use']), |
|
388 | + 'type' => isset($_POST['wpinv_discount_type']) ? $_POST['wpinv_discount_type'] : null, |
|
389 | + 'is_recurring' => isset($_POST['wpinv_discount_recurring']), |
|
390 | + 'items' => isset($_POST['wpinv_discount_items']) ? $_POST['wpinv_discount_items'] : array(), |
|
391 | + 'excluded_items' => isset($_POST['wpinv_discount_excluded_items']) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
392 | + 'max_uses' => isset($_POST['wpinv_discount_max_uses']) ? $_POST['wpinv_discount_max_uses'] : null, |
|
393 | + 'min_total' => isset($_POST['wpinv_discount_min_total']) ? $_POST['wpinv_discount_min_total'] : null, |
|
394 | + 'max_total' => isset($_POST['wpinv_discount_max_total']) ? $_POST['wpinv_discount_max_total'] : null, |
|
395 | 395 | ) |
396 | 396 | ); |
397 | 397 | |
398 | 398 | $discount->save(); |
399 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
399 | + do_action('getpaid_discount_metabox_save', $post_id, $discount); |
|
400 | 400 | } |
401 | 401 | } |
@@ -12,189 +12,189 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Discount { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission discounts. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $discounts = array(); |
|
15 | + /** |
|
16 | + * Submission discounts. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $discounts = array(); |
|
20 | + |
|
21 | + /** |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + * @param float $initial_total |
|
26 | + * @param float $recurring_total |
|
27 | + */ |
|
28 | + public function __construct( $submission, $initial_total, $recurring_total ) { |
|
29 | + |
|
30 | + // Process any existing invoice discounts. |
|
31 | + if ( $submission->has_invoice() ) { |
|
32 | + $this->discounts = $submission->get_invoice()->get_discounts(); |
|
33 | + } |
|
34 | + |
|
35 | + // Do we have a discount? |
|
36 | + $discount = $submission->get_field( 'discount' ); |
|
37 | + |
|
38 | + if ( empty( $discount ) ) { |
|
39 | + |
|
40 | + if ( isset( $this->discounts['discount_code'] ) ) { |
|
41 | + unset( $this->discounts['discount_code'] ); |
|
42 | + } |
|
43 | + |
|
44 | + return; |
|
45 | + } |
|
46 | + |
|
47 | + // Processes the discount code. |
|
48 | + $amount = max( $initial_total, $recurring_total ); |
|
49 | + $this->process_discount( $submission, $discount, $amount ); |
|
50 | + |
|
51 | + } |
|
20 | 52 | |
21 | 53 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - * @param float $initial_total |
|
26 | - * @param float $recurring_total |
|
27 | - */ |
|
28 | - public function __construct( $submission, $initial_total, $recurring_total ) { |
|
29 | - |
|
30 | - // Process any existing invoice discounts. |
|
31 | - if ( $submission->has_invoice() ) { |
|
32 | - $this->discounts = $submission->get_invoice()->get_discounts(); |
|
33 | - } |
|
34 | - |
|
35 | - // Do we have a discount? |
|
36 | - $discount = $submission->get_field( 'discount' ); |
|
37 | - |
|
38 | - if ( empty( $discount ) ) { |
|
39 | - |
|
40 | - if ( isset( $this->discounts['discount_code'] ) ) { |
|
41 | - unset( $this->discounts['discount_code'] ); |
|
42 | - } |
|
43 | - |
|
44 | - return; |
|
45 | - } |
|
46 | - |
|
47 | - // Processes the discount code. |
|
48 | - $amount = max( $initial_total, $recurring_total ); |
|
49 | - $this->process_discount( $submission, $discount, $amount ); |
|
50 | - |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Processes a submission discount. |
|
55 | - * |
|
56 | - * @param GetPaid_Payment_Form_Submission $submission |
|
57 | - * @param string $discount |
|
58 | - * @param float $amount |
|
59 | - */ |
|
60 | - public function process_discount( $submission, $discount, $amount ) { |
|
61 | - |
|
62 | - // Fetch the discount. |
|
63 | - $discount = new WPInv_Discount( $discount ); |
|
64 | - |
|
65 | - // Ensure it is active. |
|
54 | + * Processes a submission discount. |
|
55 | + * |
|
56 | + * @param GetPaid_Payment_Form_Submission $submission |
|
57 | + * @param string $discount |
|
58 | + * @param float $amount |
|
59 | + */ |
|
60 | + public function process_discount( $submission, $discount, $amount ) { |
|
61 | + |
|
62 | + // Fetch the discount. |
|
63 | + $discount = new WPInv_Discount( $discount ); |
|
64 | + |
|
65 | + // Ensure it is active. |
|
66 | 66 | if ( ! $this->is_discount_active( $discount ) ) { |
67 | - throw new Exception( __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
68 | - } |
|
69 | - |
|
70 | - // Exceeded limit. |
|
71 | - if ( $discount->has_exceeded_limit() ) { |
|
72 | - throw new Exception( __( 'This discount code has been used up', 'invoicing' ) ); |
|
73 | - } |
|
74 | - |
|
75 | - // Validate usages. |
|
76 | - $this->validate_single_use_discount( $submission, $discount ); |
|
77 | - |
|
78 | - // Validate amount. |
|
79 | - $this->validate_discount_amount( $submission, $discount, $amount ); |
|
80 | - |
|
81 | - // Save the discount. |
|
82 | - $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Validates a single use discount. |
|
87 | - * |
|
88 | - * @param WPInv_Discount $discount |
|
89 | - * @return bool |
|
90 | - */ |
|
91 | - public function is_discount_active( $discount ) { |
|
92 | - return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Returns a user's id or email. |
|
97 | - * |
|
98 | - * @param string $email |
|
99 | - * @return int|string|false |
|
100 | - */ |
|
101 | - public function get_user_id_or_email( $email ) { |
|
102 | - |
|
103 | - if ( is_user_logged_in() ) { |
|
104 | - return get_current_user_id(); |
|
105 | - } |
|
106 | - |
|
107 | - return empty( $email ) ? false : sanitize_email( $email ); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Validates a single use discount. |
|
112 | - * |
|
113 | - * @param GetPaid_Payment_Form_Submission $submission |
|
114 | - * @param WPInv_Discount $discount |
|
115 | - */ |
|
116 | - public function validate_single_use_discount( $submission, $discount ) { |
|
117 | - |
|
118 | - // Abort if it is not a single use discount. |
|
119 | - if ( ! $discount->is_single_use() ) { |
|
120 | - return; |
|
121 | - } |
|
122 | - |
|
123 | - // Ensure there is a valid billing email. |
|
124 | - $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
125 | - |
|
126 | - if ( empty( $user ) ) { |
|
127 | - throw new Exception( __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
128 | - } |
|
129 | - |
|
130 | - // Has the user used this discount code before? |
|
131 | - if ( ! $discount->is_valid_for_user( $user ) ) { |
|
132 | - throw new Exception( __( 'You have already used this discount', 'invoicing' ) ); |
|
133 | - } |
|
134 | - |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Validates the discount's amount. |
|
139 | - * |
|
140 | - * @param GetPaid_Payment_Form_Submission $submission |
|
141 | - * @param WPInv_Discount $discount |
|
142 | - * @param float $amount |
|
143 | - */ |
|
144 | - public function validate_discount_amount( $submission, $discount, $amount ) { |
|
145 | - |
|
146 | - // Validate minimum amount. |
|
147 | - if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
148 | - $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
149 | - throw new Exception( sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
150 | - } |
|
151 | - |
|
152 | - // Validate the maximum amount. |
|
153 | - if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
154 | - $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
155 | - throw new Exception( sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
156 | - } |
|
157 | - |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Calculates the discount code's amount. |
|
162 | - * |
|
163 | - * Ensure that the discount exists and has been validated before calling this method. |
|
164 | - * |
|
165 | - * @param GetPaid_Payment_Form_Submission $submission |
|
166 | - * @param WPInv_Discount $discount |
|
167 | - * @return array |
|
168 | - */ |
|
169 | - public function calculate_discount( $submission, $discount ) { |
|
170 | - |
|
171 | - $initial_discount = 0; |
|
172 | - $recurring_discount = 0; |
|
173 | - |
|
174 | - foreach ( $submission->get_items() as $item ) { |
|
175 | - |
|
176 | - // Abort if it is not valid for this item. |
|
177 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
178 | - continue; |
|
179 | - } |
|
180 | - |
|
181 | - // Calculate the initial amount... |
|
182 | - $initial_discount += $discount->get_discounted_amount( $item->get_sub_total() ); |
|
183 | - |
|
184 | - // ... and maybe the recurring amount. |
|
185 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
186 | - $recurring_discount += $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
187 | - } |
|
188 | - |
|
189 | - } |
|
190 | - |
|
191 | - return array( |
|
192 | - 'name' => 'discount_code', |
|
193 | - 'discount_code' => $discount->get_code(), |
|
194 | - 'initial_discount' => $initial_discount, |
|
195 | - 'recurring_discount' => $recurring_discount, |
|
196 | - ); |
|
197 | - |
|
198 | - } |
|
67 | + throw new Exception( __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
68 | + } |
|
69 | + |
|
70 | + // Exceeded limit. |
|
71 | + if ( $discount->has_exceeded_limit() ) { |
|
72 | + throw new Exception( __( 'This discount code has been used up', 'invoicing' ) ); |
|
73 | + } |
|
74 | + |
|
75 | + // Validate usages. |
|
76 | + $this->validate_single_use_discount( $submission, $discount ); |
|
77 | + |
|
78 | + // Validate amount. |
|
79 | + $this->validate_discount_amount( $submission, $discount, $amount ); |
|
80 | + |
|
81 | + // Save the discount. |
|
82 | + $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Validates a single use discount. |
|
87 | + * |
|
88 | + * @param WPInv_Discount $discount |
|
89 | + * @return bool |
|
90 | + */ |
|
91 | + public function is_discount_active( $discount ) { |
|
92 | + return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Returns a user's id or email. |
|
97 | + * |
|
98 | + * @param string $email |
|
99 | + * @return int|string|false |
|
100 | + */ |
|
101 | + public function get_user_id_or_email( $email ) { |
|
102 | + |
|
103 | + if ( is_user_logged_in() ) { |
|
104 | + return get_current_user_id(); |
|
105 | + } |
|
106 | + |
|
107 | + return empty( $email ) ? false : sanitize_email( $email ); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Validates a single use discount. |
|
112 | + * |
|
113 | + * @param GetPaid_Payment_Form_Submission $submission |
|
114 | + * @param WPInv_Discount $discount |
|
115 | + */ |
|
116 | + public function validate_single_use_discount( $submission, $discount ) { |
|
117 | + |
|
118 | + // Abort if it is not a single use discount. |
|
119 | + if ( ! $discount->is_single_use() ) { |
|
120 | + return; |
|
121 | + } |
|
122 | + |
|
123 | + // Ensure there is a valid billing email. |
|
124 | + $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
125 | + |
|
126 | + if ( empty( $user ) ) { |
|
127 | + throw new Exception( __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
128 | + } |
|
129 | + |
|
130 | + // Has the user used this discount code before? |
|
131 | + if ( ! $discount->is_valid_for_user( $user ) ) { |
|
132 | + throw new Exception( __( 'You have already used this discount', 'invoicing' ) ); |
|
133 | + } |
|
134 | + |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Validates the discount's amount. |
|
139 | + * |
|
140 | + * @param GetPaid_Payment_Form_Submission $submission |
|
141 | + * @param WPInv_Discount $discount |
|
142 | + * @param float $amount |
|
143 | + */ |
|
144 | + public function validate_discount_amount( $submission, $discount, $amount ) { |
|
145 | + |
|
146 | + // Validate minimum amount. |
|
147 | + if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
148 | + $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
149 | + throw new Exception( sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
150 | + } |
|
151 | + |
|
152 | + // Validate the maximum amount. |
|
153 | + if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
154 | + $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
155 | + throw new Exception( sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
156 | + } |
|
157 | + |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Calculates the discount code's amount. |
|
162 | + * |
|
163 | + * Ensure that the discount exists and has been validated before calling this method. |
|
164 | + * |
|
165 | + * @param GetPaid_Payment_Form_Submission $submission |
|
166 | + * @param WPInv_Discount $discount |
|
167 | + * @return array |
|
168 | + */ |
|
169 | + public function calculate_discount( $submission, $discount ) { |
|
170 | + |
|
171 | + $initial_discount = 0; |
|
172 | + $recurring_discount = 0; |
|
173 | + |
|
174 | + foreach ( $submission->get_items() as $item ) { |
|
175 | + |
|
176 | + // Abort if it is not valid for this item. |
|
177 | + if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
178 | + continue; |
|
179 | + } |
|
180 | + |
|
181 | + // Calculate the initial amount... |
|
182 | + $initial_discount += $discount->get_discounted_amount( $item->get_sub_total() ); |
|
183 | + |
|
184 | + // ... and maybe the recurring amount. |
|
185 | + if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
186 | + $recurring_discount += $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
187 | + } |
|
188 | + |
|
189 | + } |
|
190 | + |
|
191 | + return array( |
|
192 | + 'name' => 'discount_code', |
|
193 | + 'discount_code' => $discount->get_code(), |
|
194 | + 'initial_discount' => $initial_discount, |
|
195 | + 'recurring_discount' => $recurring_discount, |
|
196 | + ); |
|
197 | + |
|
198 | + } |
|
199 | 199 | |
200 | 200 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission discount class |
@@ -25,28 +25,28 @@ discard block |
||
25 | 25 | * @param float $initial_total |
26 | 26 | * @param float $recurring_total |
27 | 27 | */ |
28 | - public function __construct( $submission, $initial_total, $recurring_total ) { |
|
28 | + public function __construct($submission, $initial_total, $recurring_total) { |
|
29 | 29 | |
30 | 30 | // Process any existing invoice discounts. |
31 | - if ( $submission->has_invoice() ) { |
|
31 | + if ($submission->has_invoice()) { |
|
32 | 32 | $this->discounts = $submission->get_invoice()->get_discounts(); |
33 | 33 | } |
34 | 34 | |
35 | 35 | // Do we have a discount? |
36 | - $discount = $submission->get_field( 'discount' ); |
|
36 | + $discount = $submission->get_field('discount'); |
|
37 | 37 | |
38 | - if ( empty( $discount ) ) { |
|
38 | + if (empty($discount)) { |
|
39 | 39 | |
40 | - if ( isset( $this->discounts['discount_code'] ) ) { |
|
41 | - unset( $this->discounts['discount_code'] ); |
|
40 | + if (isset($this->discounts['discount_code'])) { |
|
41 | + unset($this->discounts['discount_code']); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | return; |
45 | 45 | } |
46 | 46 | |
47 | 47 | // Processes the discount code. |
48 | - $amount = max( $initial_total, $recurring_total ); |
|
49 | - $this->process_discount( $submission, $discount, $amount ); |
|
48 | + $amount = max($initial_total, $recurring_total); |
|
49 | + $this->process_discount($submission, $discount, $amount); |
|
50 | 50 | |
51 | 51 | } |
52 | 52 | |
@@ -57,29 +57,29 @@ discard block |
||
57 | 57 | * @param string $discount |
58 | 58 | * @param float $amount |
59 | 59 | */ |
60 | - public function process_discount( $submission, $discount, $amount ) { |
|
60 | + public function process_discount($submission, $discount, $amount) { |
|
61 | 61 | |
62 | 62 | // Fetch the discount. |
63 | - $discount = new WPInv_Discount( $discount ); |
|
63 | + $discount = new WPInv_Discount($discount); |
|
64 | 64 | |
65 | 65 | // Ensure it is active. |
66 | - if ( ! $this->is_discount_active( $discount ) ) { |
|
67 | - throw new Exception( __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
66 | + if (!$this->is_discount_active($discount)) { |
|
67 | + throw new Exception(__('Invalid or expired discount code', 'invoicing')); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | // Exceeded limit. |
71 | - if ( $discount->has_exceeded_limit() ) { |
|
72 | - throw new Exception( __( 'This discount code has been used up', 'invoicing' ) ); |
|
71 | + if ($discount->has_exceeded_limit()) { |
|
72 | + throw new Exception(__('This discount code has been used up', 'invoicing')); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // Validate usages. |
76 | - $this->validate_single_use_discount( $submission, $discount ); |
|
76 | + $this->validate_single_use_discount($submission, $discount); |
|
77 | 77 | |
78 | 78 | // Validate amount. |
79 | - $this->validate_discount_amount( $submission, $discount, $amount ); |
|
79 | + $this->validate_discount_amount($submission, $discount, $amount); |
|
80 | 80 | |
81 | 81 | // Save the discount. |
82 | - $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
82 | + $this->discounts['discount_code'] = $this->calculate_discount($submission, $discount); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | * @param WPInv_Discount $discount |
89 | 89 | * @return bool |
90 | 90 | */ |
91 | - public function is_discount_active( $discount ) { |
|
92 | - return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
91 | + public function is_discount_active($discount) { |
|
92 | + return $discount->exists() && $discount->is_active() && $discount->has_started() && !$discount->is_expired(); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -98,13 +98,13 @@ discard block |
||
98 | 98 | * @param string $email |
99 | 99 | * @return int|string|false |
100 | 100 | */ |
101 | - public function get_user_id_or_email( $email ) { |
|
101 | + public function get_user_id_or_email($email) { |
|
102 | 102 | |
103 | - if ( is_user_logged_in() ) { |
|
103 | + if (is_user_logged_in()) { |
|
104 | 104 | return get_current_user_id(); |
105 | 105 | } |
106 | 106 | |
107 | - return empty( $email ) ? false : sanitize_email( $email ); |
|
107 | + return empty($email) ? false : sanitize_email($email); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -113,23 +113,23 @@ discard block |
||
113 | 113 | * @param GetPaid_Payment_Form_Submission $submission |
114 | 114 | * @param WPInv_Discount $discount |
115 | 115 | */ |
116 | - public function validate_single_use_discount( $submission, $discount ) { |
|
116 | + public function validate_single_use_discount($submission, $discount) { |
|
117 | 117 | |
118 | 118 | // Abort if it is not a single use discount. |
119 | - if ( ! $discount->is_single_use() ) { |
|
119 | + if (!$discount->is_single_use()) { |
|
120 | 120 | return; |
121 | 121 | } |
122 | 122 | |
123 | 123 | // Ensure there is a valid billing email. |
124 | - $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
124 | + $user = $this->get_user_id_or_email($submission->get_billing_email()); |
|
125 | 125 | |
126 | - if ( empty( $user ) ) { |
|
127 | - throw new Exception( __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
126 | + if (empty($user)) { |
|
127 | + throw new Exception(__('You need to either log in or enter your billing email before applying this discount', 'invoicing')); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | // Has the user used this discount code before? |
131 | - if ( ! $discount->is_valid_for_user( $user ) ) { |
|
132 | - throw new Exception( __( 'You have already used this discount', 'invoicing' ) ); |
|
131 | + if (!$discount->is_valid_for_user($user)) { |
|
132 | + throw new Exception(__('You have already used this discount', 'invoicing')); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | } |
@@ -141,18 +141,18 @@ discard block |
||
141 | 141 | * @param WPInv_Discount $discount |
142 | 142 | * @param float $amount |
143 | 143 | */ |
144 | - public function validate_discount_amount( $submission, $discount, $amount ) { |
|
144 | + public function validate_discount_amount($submission, $discount, $amount) { |
|
145 | 145 | |
146 | 146 | // Validate minimum amount. |
147 | - if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
148 | - $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
149 | - throw new Exception( sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
147 | + if (!$discount->is_minimum_amount_met($amount)) { |
|
148 | + $min = wpinv_price($discount->get_minimum_total(), $submission->get_currency()); |
|
149 | + throw new Exception(sprintf(__('The minimum total for using this discount is %s', 'invoicing'), $min)); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | // Validate the maximum amount. |
153 | - if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
154 | - $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
155 | - throw new Exception( sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
153 | + if (!$discount->is_maximum_amount_met($amount)) { |
|
154 | + $max = wpinv_price($discount->get_maximum_total(), $submission->get_currency()); |
|
155 | + throw new Exception(sprintf(__('The maximum total for using this discount is %s', 'invoicing'), $max)); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | } |
@@ -166,24 +166,24 @@ discard block |
||
166 | 166 | * @param WPInv_Discount $discount |
167 | 167 | * @return array |
168 | 168 | */ |
169 | - public function calculate_discount( $submission, $discount ) { |
|
169 | + public function calculate_discount($submission, $discount) { |
|
170 | 170 | |
171 | 171 | $initial_discount = 0; |
172 | 172 | $recurring_discount = 0; |
173 | 173 | |
174 | - foreach ( $submission->get_items() as $item ) { |
|
174 | + foreach ($submission->get_items() as $item) { |
|
175 | 175 | |
176 | 176 | // Abort if it is not valid for this item. |
177 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
177 | + if (!$discount->is_valid_for_items(array($item->get_id()))) { |
|
178 | 178 | continue; |
179 | 179 | } |
180 | 180 | |
181 | 181 | // Calculate the initial amount... |
182 | - $initial_discount += $discount->get_discounted_amount( $item->get_sub_total() ); |
|
182 | + $initial_discount += $discount->get_discounted_amount($item->get_sub_total()); |
|
183 | 183 | |
184 | 184 | // ... and maybe the recurring amount. |
185 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
186 | - $recurring_discount += $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
185 | + if ($item->is_recurring() && $discount->is_recurring()) { |
|
186 | + $recurring_discount += $discount->get_discounted_amount($item->get_recurring_sub_total()); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | } |