-
Notifications
You must be signed in to change notification settings - Fork 473
/
edit-discount.php
executable file
·178 lines (175 loc) · 8.51 KB
/
edit-discount.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/**
* Edit Discount Page
*
* @package EDD
* @subpackage Admin/Discounts
* @copyright Copyright (c) 2013, Pippin Williamson
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! isset( $_GET['discount'] ) || ! is_numeric( $_GET['discount'] ) ) {
wp_die( __( 'Something went wrong.', 'edd' ), __( 'Error', 'edd' ) );
}
$discount_id = absint( $_GET['discount'] );
$discount = edd_get_discount( $discount_id );
$product_reqs = edd_get_discount_product_reqs( $discount_id );
$excluded_products = edd_get_discount_excluded_products( $discount_id );
$condition = edd_get_discount_product_condition( $discount_id );
$single_use = edd_discount_is_single_use( $discount_id );
?>
<h2><?php _e( 'Edit Discount', 'edd' ); ?> - <a href="<?php echo admin_url( 'edit.php?post_type=download&page=edd-discounts' ); ?>" class="button-secondary"><?php _e( 'Go Back', 'edd' ); ?></a></h2>
<form id="edd-edit-discount" action="" method="post">
<?php do_action( 'edd_edit_discount_form_top', $discount_id, $discount ); ?>
<table class="form-table">
<tbody>
<tr class="form-field">
<th scope="row" valign="top">
<label for="edd-name"><?php _e( 'Name', 'edd' ); ?></label>
</th>
<td>
<input name="name" id="edd-name" type="text" value="<?php echo esc_attr( stripslashes( $discount->post_title ) ); ?>" style="width: 300px;"/>
<p class="description"><?php _e( 'The name of this discount', 'edd' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="edd-code"><?php _e( 'Code', 'edd' ); ?></label>
</th>
<td>
<input type="text" id="edd-code" name="code" value="<?php echo esc_attr( edd_get_discount_code( $discount_id ) ); ?>" style="width: 300px;"/>
<p class="description"><?php _e( 'Enter a code for this discount, such as 10PERCENT', 'edd' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="edd-type"><?php _e( 'Type', 'edd' ); ?></label>
</th>
<td>
<select name="type" id="edd-type">
<option value="percent" <?php selected( edd_get_discount_type( $discount_id ), 'percent' ); ?>><?php _e( 'Percentage', 'edd' ); ?></option>
<option value="flat"<?php selected( edd_get_discount_type( $discount_id ), 'flat' ); ?>><?php _e( 'Flat amount', 'edd' ); ?></option>
</select>
<p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'edd' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="edd-amount"><?php _e( 'Amount', 'edd' ); ?></label>
</th>
<td>
<input type="text" id="edd-amount" name="amount" value="<?php echo esc_attr( edd_get_discount_amount( $discount_id ) ); ?>" style="width: 40px;"/>
<p class="description"><?php _e( 'The amount of this discount code.', 'edd' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="edd-products"><?php printf( __( '%s Requirements', 'edd' ), edd_get_label_singular() ); ?></label>
</th>
<td>
<p>
<select id="edd-product-condition" name="product_condition">
<option value="all"<?php selected( 'all', $condition ); ?>><?php printf( __( 'All Selected %s', 'edd' ), edd_get_label_plural() ); ?></option>
<option value="any"<?php selected( 'any', $condition ); ?>><?php printf( __( 'Any Selected %s', 'edd' ), edd_get_label_singular() ); ?></option>
</select>
<label for="edd-product-condition"><?php _e( 'Condition', 'edd' ); ?></label>
</p>
<?php echo EDD()->html->product_dropdown( array(
'name' => 'products[]',
'selected' => $excluded_products,
'multiple' => true,
'chosen' => true
) ); ?><br/>
<p class="description"><?php printf( __( '%s required to be purchased for this discount.', 'edd' ), edd_get_label_plural() ); ?></p>
<p>
<label for="edd-non-global-discount">
<input type="checkbox" id="edd-non-global-discount" name="not_global" value="1"<?php checked( true, edd_is_discount_not_global( $discount_id ) ); ?>/>
<?php printf( __( 'Apply discount only to selected %s?', 'edd' ), edd_get_label_plural() ); ?>
</label>
</p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="edd-excluded-products"><?php printf( __( 'Excluded %s', 'edd' ), edd_get_label_plural() ); ?></label>
</th>
<td>
<?php echo EDD()->html->product_dropdown( array(
'name' => 'excluded-products[]',
'selected' => $excluded_products,
'multiple' => true,
'chosen' => true
) ); ?><br/>
<p class="description"><?php printf( __( '%s that this discount code cannot be applied to.', 'edd' ), edd_get_label_plural() ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="edd-start"><?php _e( 'Start date', 'edd' ); ?></label>
</th>
<td>
<input name="start" id="edd-start" type="text" value="<?php echo esc_attr( edd_get_discount_start_date( $discount_id ) ); ?>" style="width: 300px;" class="edd_datepicker"/>
<p class="description"><?php _e( 'Enter the start date for this discount code in the format of mm/dd/yyyy. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'edd' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="edd-expiration"><?php _e( 'Expiration date', 'edd' ); ?></label>
</th>
<td>
<input name="expiration" id="edd-expiration" type="text" value="<?php echo esc_attr( edd_get_discount_expiration( $discount_id ) ); ?>" style="width: 300px;" class="edd_datepicker"/>
<p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of mm/dd/yyyy. For no expiration, leave blank', 'edd' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="edd-max-uses"><?php _e( 'Max Uses', 'edd' ); ?></label>
</th>
<td>
<input type="text" id="edd-max-uses" name="max" value="<?php echo esc_attr( edd_get_discount_max_uses( $discount_id ) ); ?>" style="width: 40px;"/>
<p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'edd' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="edd-min-cart-amount"><?php _e( 'Minimum Amount', 'edd' ); ?></label>
</th>
<td>
<input type="text" id="edd-min-cart-amount" name="min_price" value="<?php echo esc_attr( edd_get_discount_min_price( $discount_id ) ); ?>" style="width: 40px;"/>
<p class="description"><?php _e( 'The minimum amount that must be purchased before this discount can be used. Leave blank for no minimum.', 'edd' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="edd-status"><?php _e( 'Status', 'edd' ); ?></label>
</th>
<td>
<select name="status" id="edd-status">
<option value="active" <?php selected( $discount->post_status, 'active' ); ?>><?php _e( 'Active', 'edd' ); ?></option>
<option value="inactive"<?php selected( $discount->post_status, 'inactive' ); ?>><?php _e( 'Inactive', 'edd' ); ?></option>
</select>
<p class="description"><?php _e( 'The status of this discount code.', 'edd' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="edd-use-once"><?php _e( 'Use Once Per Customer', 'edd' ); ?></label>
</th>
<td>
<input type="checkbox" id="edd-use-once" name="use_once" value="1"<?php checked( true, $single_use ); ?>/>
<span class="description"><?php _e( 'Limit this discount to a single-use per customer?', 'edd' ); ?></span>
</td>
</tr>
</tbody>
</table>
<?php do_action( 'edd_edit_discount_form_bottom', $discount_id, $discount ); ?>
<p class="submit">
<input type="hidden" name="edd-action" value="edit_discount"/>
<input type="hidden" name="discount-id" value="<?php echo absint( $_GET['discount'] ); ?>"/>
<input type="hidden" name="edd-redirect" value="<?php echo esc_url( admin_url( 'edit.php?post_type=download&page=edd-discounts' ) ); ?>"/>
<input type="hidden" name="edd-discount-nonce" value="<?php echo wp_create_nonce( 'edd_discount_nonce' ); ?>"/>
<input type="submit" value="<?php _e( 'Update Discount Code', 'edd' ); ?>" class="button-primary"/>
</p>
</form>