customers
2 months ago
orders
4 months ago
subscriptions
3 months ago
add-edit-coupon.php
2 years ago
add-edit-plan-group.php
1 year ago
add-edit-plan.php
1 month ago
checkout-field-item.php
3 years ago
checkout-fields.php
3 years ago
coupons-page-sidebar.php
3 years ago
groups-page-sidebar.php
3 years ago
index.php
3 years ago
payment-method-list.php
3 years ago
plans-page-sidebar.php
3 years ago
tax-rates-setup.php
3 years ago
add-edit-coupon.php
195 lines
| 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_type', |
| 39 | 'type' => 'select', |
| 40 | 'label' => esc_html__('Coupon Type', 'wp-user-avatar'), |
| 41 | 'options' => [ |
| 42 | 'recurring' => esc_html__('Recurring', 'wp-user-avatar'), |
| 43 | 'one_time' => esc_html__('First Payment Only', 'wp-user-avatar') |
| 44 | ], |
| 45 | 'description' => esc_html__('Selecting "First Payment Only" applies the coupon discount only to the first payment while "Recurring" applies the discount to all payments.', 'wp-user-avatar') |
| 46 | ], |
| 47 | [ |
| 48 | 'id' => 'coupon_application', |
| 49 | 'type' => 'radio', |
| 50 | 'label' => esc_html__('Coupon Application', 'wp-user-avatar'), |
| 51 | 'options' => [ |
| 52 | 'acquisition' => esc_html__('To new purchases only', 'wp-user-avatar'), |
| 53 | 'retention' => esc_html__('To existing purchase (upgrades & downgrades)', 'wp-user-avatar'), |
| 54 | 'any' => esc_html__('To both new and existing purchases', 'wp-user-avatar') |
| 55 | ], |
| 56 | 'description' => esc_html__('Select where members can apply this coupon.', 'wp-user-avatar') |
| 57 | ], |
| 58 | [ |
| 59 | 'id' => 'is_onetime_use', |
| 60 | 'type' => 'checkbox', |
| 61 | 'label' => esc_html__('Use Once Per Customer', 'wp-user-avatar'), |
| 62 | 'checkbox_label' => esc_html__('Prevent customers from using this discount more than once.', 'wp-user-avatar') |
| 63 | ] |
| 64 | ]; |
| 65 | |
| 66 | $redemption_settings = [ |
| 67 | [ |
| 68 | 'id' => 'plan_ids', |
| 69 | 'type' => 'select', |
| 70 | 'multiple' => true, |
| 71 | 'label' => esc_html__('Membership Plans', 'wp-user-avatar'), |
| 72 | 'options' => array_reduce(PlanRepository::init()->retrieveAll(), function ($carry, PlanEntity $plan) { |
| 73 | $carry[$plan->get_id()] = $plan->get_name(); |
| 74 | |
| 75 | return $carry; |
| 76 | }, []), |
| 77 | 'description' => esc_html__('Select membership plans this coupon can only be applied to. Leave blank for all plans.', 'wp-user-avatar') |
| 78 | ], |
| 79 | [ |
| 80 | 'id' => 'start_date', |
| 81 | 'type' => 'text', |
| 82 | 'placeholder' => 'yyyy-mm-dd', |
| 83 | 'label' => esc_html__('Start Date', 'wp-user-avatar'), |
| 84 | 'description' => sprintf( |
| 85 | esc_html__('Enter the date that this coupon will be valid from. Leave blank for no start date. (UTC %s)', 'wp-user-avatar'), |
| 86 | (new DateTime())->setTimeZone(wp_timezone())->format('P') |
| 87 | ) |
| 88 | ], |
| 89 | [ |
| 90 | 'id' => 'end_date', |
| 91 | 'type' => 'text', |
| 92 | 'placeholder' => 'yyyy-mm-dd', |
| 93 | 'label' => esc_html__('End Date', 'wp-user-avatar'), |
| 94 | 'description' => sprintf( |
| 95 | esc_html__('Enter the date that this coupon will expire on. Leave blank for no end date. (UTC %s)', 'wp-user-avatar'), |
| 96 | (new DateTime())->setTimeZone(wp_timezone())->format('P') |
| 97 | ) |
| 98 | ], |
| 99 | [ |
| 100 | 'id' => 'usage_limit', |
| 101 | 'type' => 'text', |
| 102 | 'placeholder' => esc_html__('Unlimited', 'wp-user-avatar'), |
| 103 | 'label' => esc_html__('Maximum Redemptions ', 'wp-user-avatar'), |
| 104 | 'description' => esc_html__('Limit the total amount of redemptions for this coupon. Leave blank for unlimited.', 'wp-user-avatar') |
| 105 | ], |
| 106 | ]; |
| 107 | |
| 108 | $coupon_data = CouponFactory::fromId(absint(ppressGET_var('id'))); |
| 109 | |
| 110 | if (ppressGET_var('ppress_coupon_action') == 'edit' && ! $coupon_data->exists()) { |
| 111 | ppress_content_http_redirect(PPRESS_MEMBERSHIP_COUPONS_SETTINGS_PAGE); |
| 112 | |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | add_action('add_meta_boxes', function () use ($coupon_details, $redemption_settings, $coupon_data) { |
| 117 | |
| 118 | add_meta_box( |
| 119 | 'ppress-membership-coupon-content', |
| 120 | esc_html__('Coupon Details', 'wp-user-avatar'), |
| 121 | function () use ($coupon_details, $coupon_data) { |
| 122 | echo '<div class="ppress-membership-coupon-details">'; |
| 123 | (new SettingsFieldsParser($coupon_details, $coupon_data, 'ppress-coupon-control'))->build(); |
| 124 | echo '</div>'; |
| 125 | }, |
| 126 | 'ppmembershipcoupon' |
| 127 | ); |
| 128 | |
| 129 | add_meta_box( |
| 130 | 'ppress-subscription-coupon-settings', |
| 131 | esc_html__('Redemption Settings', 'wp-user-avatar'), |
| 132 | function () use ($redemption_settings, $coupon_data) { |
| 133 | echo '<div class="ppress-subscription-coupon-settings">'; |
| 134 | (new SettingsFieldsParser($redemption_settings, $coupon_data))->build(); |
| 135 | echo '</div>'; |
| 136 | }, |
| 137 | 'ppmembershipcoupon' |
| 138 | ); |
| 139 | |
| 140 | add_meta_box( |
| 141 | 'submitdiv', |
| 142 | __('Publish', 'wp-user-avatar'), |
| 143 | function () { |
| 144 | require dirname(__FILE__) . '/coupons-page-sidebar.php'; |
| 145 | }, |
| 146 | 'ppmembershipcoupon', |
| 147 | 'sidebar' |
| 148 | ); |
| 149 | }); |
| 150 | |
| 151 | do_action('add_meta_boxes', 'ppmembershipcoupon', new WP_Post(new stdClass())); |
| 152 | ?> |
| 153 | <style type="text/css"> |
| 154 | .ppview .postbox .ppress-amount-type-wrapper select { |
| 155 | border-top-left-radius: 0; |
| 156 | border-bottom-left-radius: 0; |
| 157 | width: 50px !important; |
| 158 | max-width: none !important; |
| 159 | } |
| 160 | |
| 161 | .ppview .postbox .ppress-amount-type-wrapper input#amount { |
| 162 | width: 300px !important; |
| 163 | border-top-right-radius: 0; |
| 164 | border-bottom-right-radius: 0; |
| 165 | margin-right: -2px; |
| 166 | padding: 0 8px; |
| 167 | max-width: 125px !important; |
| 168 | } |
| 169 | |
| 170 | .ppview .postbox .ppress-amount-type-wrapper { |
| 171 | position: relative; |
| 172 | display: flex |
| 173 | } |
| 174 | |
| 175 | .ppview .postbox .ppress-amount-type-wrapper input:focus { |
| 176 | z-index: 2 |
| 177 | } |
| 178 | |
| 179 | .ppview #field-role-coupon_application label { |
| 180 | display: block; |
| 181 | margin: 10px 0; |
| 182 | } |
| 183 | </style> |
| 184 | <div id="poststuff"> |
| 185 | <div id="post-body" class="metabox-holder columns-2"> |
| 186 | |
| 187 | <div id="postbox-container-1" class="postbox-container"> |
| 188 | <?php do_meta_boxes('ppmembershipcoupon', 'sidebar', ''); ?> |
| 189 | </div> |
| 190 | <div id="postbox-container-2" class="postbox-container"> |
| 191 | <?php do_meta_boxes('ppmembershipcoupon', 'advanced', ''); ?> |
| 192 | </div> |
| 193 | </div> |
| 194 | <br class="clear"> |
| 195 | </div> |