PluginProbe
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 4.0.3
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v4.0.3
4.17.3 4.17.2 4.17.1 4.17.0 4.16.19 4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 All 220 releases
wp-user-avatar / src / Admin / SettingsPages / Membership / views / add-edit-coupon.php
add-edit-coupon.php
179 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use ProfilePress\Core\Admin\SettingsPages\Membership\SettingsFieldsParser;
4 use ProfilePress\Core\Membership\Models\Coupon\CouponFactory;
5 use ProfilePress\Core\Membership\Models\Plan\PlanEntity;
6 use ProfilePress\Core\Membership\Repositories\PlanRepository;
7
8 add_action('admin_footer', function () {
9 ?>
10 <script type="text/javascript">
11 jQuery(function () {
12 jQuery('#plan_ids').select2();
13 jQuery('#start_date, #end_date').flatpickr({dateFormat: "Y-m-d", allowInput: true});
14 });
15 </script>
16 <?php
17 });
18
19 $coupon_details = [
20 [
21 'id' => 'code',
22 'type' => 'text',
23 'label' => esc_html__('Coupon Code', 'wp-user-avatar'),
24 'description' => esc_html__('Enter a unique coupon code. Leave empty to generate a code for you on form submission.', 'wp-user-avatar')
25 ],
26 [
27 'id' => 'description',
28 'type' => 'textarea',
29 'label' => esc_html__('Description', 'wp-user-avatar'),
30 'description' => esc_html__('A description of this coupon.', 'wp-user-avatar')
31 ],
32 [
33 'id' => 'discount',
34 'type' => 'discount',
35 'label' => esc_html__('Discount', 'wp-user-avatar'),
36 ],
37 [
38 'id' => 'coupon_application',
39 'type' => 'radio',
40 'label' => esc_html__('Coupon Application', 'wp-user-avatar'),
41 'options' => [
42 'acquisition' => esc_html__('To new purchases only', 'wp-user-avatar'),
43 'retention' => esc_html__('To existing purchase (upgrades)', 'wp-user-avatar'),
44 'any' => esc_html__('To both new and existing purchases', 'wp-user-avatar')
45 ],
46 /** @todo add support for when upgrade/downgrade is live */
47 'description' => esc_html__('Select where members can apply this coupon.', 'wp-user-avatar')
48 ]
49 ];
50
51 $redemption_settings = [
52 [
53 'id' => 'plan_ids',
54 'type' => 'select',
55 'multiple' => true,
56 'label' => esc_html__('Membership Plans', 'wp-user-avatar'),
57 'options' => array_reduce(PlanRepository::init()->retrieveAll(), function ($carry, PlanEntity $plan) {
58 $carry[$plan->get_id()] = $plan->get_name();
59
60 return $carry;
61 }, []),
62 'description' => esc_html__('Select membership plans this coupon can only be applied to. Leave blank for all plans.', 'wp-user-avatar')
63 ],
64 [
65 'id' => 'start_date',
66 'type' => 'text',
67 'placeholder' => 'yyyy-mm-dd',
68 'label' => esc_html__('Start Date', 'wp-user-avatar'),
69 'description' => sprintf(
70 esc_html__('Enter the date that this coupon will be valid from. Leave blank for no start date. (UTC %s)', 'wp-user-avatar'),
71 (new DateTime())->setTimeZone(wp_timezone())->format('P')
72 )
73 ],
74 [
75 'id' => 'end_date',
76 'type' => 'text',
77 'placeholder' => 'yyyy-mm-dd',
78 'label' => esc_html__('End Date', 'wp-user-avatar'),
79 'description' => sprintf(
80 esc_html__('Enter the date that this coupon will expire on. Leave blank for no end date. (UTC %s)', 'wp-user-avatar'),
81 (new DateTime())->setTimeZone(wp_timezone())->format('P')
82 )
83 ],
84 [
85 'id' => 'usage_limit',
86 'type' => 'text',
87 'placeholder' => esc_html__('Unlimited', 'wp-user-avatar'),
88 'label' => esc_html__('Maximum Redemptions ', 'wp-user-avatar'),
89 'description' => esc_html__('Limit the total amount of redemptions for this coupon. Leave blank for unlimited.', 'wp-user-avatar')
90 ],
91 ];
92
93 $coupon_data = CouponFactory::fromId(absint(ppressGET_var('id')));
94
95 if (ppressGET_var('ppress_coupon_action') =='edit' && ! $coupon_data->exists()) {
96 ppress_content_http_redirect(PPRESS_MEMBERSHIP_COUPONS_SETTINGS_PAGE);
97 return;
98 }
99
100 add_action('add_meta_boxes', function () use ($coupon_details, $redemption_settings, $coupon_data) {
101
102 add_meta_box(
103 'ppress-membership-coupon-content',
104 esc_html__('Coupon Details', 'wp-user-avatar'),
105 function () use ($coupon_details, $coupon_data) {
106 echo '<div class="ppress-membership-coupon-details">';
107 (new SettingsFieldsParser($coupon_details, $coupon_data, 'ppress-coupon-control'))->build();
108 echo '</div>';
109 },
110 'ppmembershipcoupon'
111 );
112
113 add_meta_box(
114 'ppress-subscription-coupon-settings',
115 esc_html__('Redemption Settings', 'wp-user-avatar'),
116 function () use ($redemption_settings, $coupon_data) {
117 echo '<div class="ppress-subscription-coupon-settings">';
118 (new SettingsFieldsParser($redemption_settings, $coupon_data))->build();
119 echo '</div>';
120 },
121 'ppmembershipcoupon'
122 );
123
124 add_meta_box(
125 'submitdiv',
126 __('Publish', 'wp-user-avatar'),
127 function () {
128 require dirname(__FILE__) . '/coupons-page-sidebar.php';
129 },
130 'ppmembershipcoupon',
131 'sidebar'
132 );
133 });
134
135 do_action('add_meta_boxes', 'ppmembershipcoupon', new WP_Post(new stdClass()));
136 ?>
137 <style type="text/css">
138 .ppview .postbox .ppress-amount-type-wrapper select {
139 border-top-left-radius: 0;
140 border-bottom-left-radius: 0;
141 width: 50px !important;
142 max-width: none !important;
143 }
144
145 .ppview .postbox .ppress-amount-type-wrapper input#amount {
146 width: 300px !important;
147 border-top-right-radius: 0;
148 border-bottom-right-radius: 0;
149 margin-right: -2px;
150 padding: 0 8px;
151 max-width: 125px !important;
152 }
153
154 .ppview .postbox .ppress-amount-type-wrapper {
155 position: relative;
156 display: flex
157 }
158
159 .ppview .postbox .ppress-amount-type-wrapper input:focus {
160 z-index: 2
161 }
162
163 .ppview #field-role-coupon_application label {
164 display: block;
165 margin: 10px 0;
166 }
167 </style>
168 <div id="poststuff">
169 <div id="post-body" class="metabox-holder columns-2">
170
171 <div id="postbox-container-1" class="postbox-container">
172 <?php do_meta_boxes('ppmembershipcoupon', 'sidebar', ''); ?>
173 </div>
174 <div id="postbox-container-2" class="postbox-container">
175 <?php do_meta_boxes('ppmembershipcoupon', 'advanced', ''); ?>
176 </div>
177 </div>
178 <br class="clear">
179 </div>