customers
4 years ago
orders
4 years ago
subscriptions
4 years ago
add-edit-coupon.php
4 years ago
add-edit-plan.php
4 years ago
checkout-field-item.php
4 years ago
checkout-fields.php
4 years ago
coupons-page-sidebar.php
4 years ago
index.php
4 years ago
payment-method-list.php
4 years ago
plans-page-sidebar.php
4 years ago
tax-rates-setup.php
4 years ago
add-edit-plan.php
201 lines
| 1 | <?php |
| 2 | |
| 3 | use ProfilePress\Core\Admin\SettingsPages\Membership\SettingsFieldsParser; |
| 4 | use ProfilePress\Core\Membership\Models\Subscription\SubscriptionBillingFrequency; |
| 5 | use ProfilePress\Core\Membership\Models\Subscription\SubscriptionTrialPeriod; |
| 6 | |
| 7 | $plan_details = [ |
| 8 | [ |
| 9 | 'id' => 'name', |
| 10 | 'type' => 'text', |
| 11 | 'label' => esc_html__('Plan Name', 'wp-user-avatar') |
| 12 | ], |
| 13 | [ |
| 14 | 'id' => 'description', |
| 15 | 'type' => 'wp_editor', |
| 16 | 'label' => esc_html__('Plan Description', 'wp-user-avatar'), |
| 17 | 'description' => esc_html__('A description of this plan. This will be displayed on the checkout page.', 'wp-user-avatar') |
| 18 | ], |
| 19 | [ |
| 20 | 'id' => 'price', |
| 21 | 'type' => 'price', |
| 22 | 'label' => esc_html__('Price', 'wp-user-avatar') . sprintf(' (%s)', ppress_get_currency_symbol()), |
| 23 | 'description' => esc_html__('The price of this membership plan. Enter 0 to make this plan free.', 'wp-user-avatar') |
| 24 | ] |
| 25 | ]; |
| 26 | |
| 27 | $subscription_settings = [ |
| 28 | [ |
| 29 | 'id' => 'billing_frequency', |
| 30 | 'type' => 'select', |
| 31 | 'label' => esc_html__('Billing Frequency', 'wp-user-avatar'), |
| 32 | 'options' => SubscriptionBillingFrequency::get_all() |
| 33 | ], |
| 34 | [ |
| 35 | 'id' => 'subscription_length', |
| 36 | 'type' => 'select', |
| 37 | 'label' => esc_html__('Subscription Length', 'wp-user-avatar'), |
| 38 | 'options' => [ |
| 39 | 'renew_indefinitely' => esc_html__('Renew indefinitely until member cancels', 'wp-user-avatar'), |
| 40 | 'fixed' => esc_html__('Fixed number of payments', 'wp-user-avatar') |
| 41 | ] |
| 42 | ], |
| 43 | [ |
| 44 | 'id' => 'total_payments', |
| 45 | 'type' => 'number', |
| 46 | 'label' => esc_html__('Total Payments', 'wp-user-avatar'), |
| 47 | 'description' => esc_html__('The total number of recurring billing cycles including the trial period (if applicable). Keep in mind that once a member has completed the last payment, the subscription will not expire — essentially giving them lifetime access.', 'wp-user-avatar') |
| 48 | ], |
| 49 | [ |
| 50 | 'id' => 'signup_fee', |
| 51 | 'type' => 'price', |
| 52 | 'label' => esc_html__('Signup Fee', 'wp-user-avatar') . sprintf(' (%s)', ppress_get_currency_symbol()), |
| 53 | 'description' => esc_html__('Optional signup fee to charge subscribers for the first billing cycle.', 'wp-user-avatar') |
| 54 | ], |
| 55 | [ |
| 56 | 'id' => 'free_trial', |
| 57 | 'type' => 'select', |
| 58 | 'options' => SubscriptionTrialPeriod::get_all(), |
| 59 | 'label' => esc_html__('Free Trial', 'wp-user-avatar'), |
| 60 | 'description' => esc_html__('Allow members free access for a specified duration of time before charging them.', 'wp-user-avatar') |
| 61 | ] |
| 62 | ]; |
| 63 | |
| 64 | $plan_data = ppress_get_plan(absint(ppressGET_var('id'))); |
| 65 | |
| 66 | if (ppressGET_var('ppress_subp_action') == 'edit' && ! $plan_data->exists()) { |
| 67 | ppress_content_http_redirect(PPRESS_MEMBERSHIP_PLANS_SETTINGS_SLUG); |
| 68 | |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | add_action('add_meta_boxes', function () use ($subscription_settings, $plan_details, $plan_data) { |
| 73 | add_meta_box( |
| 74 | 'ppress-membership-plan-content', |
| 75 | esc_html__('Plan Details', 'wp-user-avatar'), |
| 76 | function () use ($plan_details, $plan_data) { |
| 77 | echo '<div class="ppress-membership-plan-details">'; |
| 78 | (new SettingsFieldsParser($plan_details, $plan_data))->build(); |
| 79 | echo '</div>'; |
| 80 | }, |
| 81 | 'ppmembershipplan' |
| 82 | ); |
| 83 | |
| 84 | add_meta_box( |
| 85 | 'ppress-subscription-plan-settings', |
| 86 | esc_html__('Subscription Settings', 'wp-user-avatar'), |
| 87 | function () use ($subscription_settings, $plan_data) { |
| 88 | echo '<div class="ppress-subscription-plan-settings">'; |
| 89 | (new SettingsFieldsParser($subscription_settings, $plan_data))->build(); |
| 90 | echo '</div>'; |
| 91 | }, |
| 92 | 'ppmembershipplan' |
| 93 | ); |
| 94 | |
| 95 | add_meta_box( |
| 96 | 'submitdiv', |
| 97 | __('Publish', 'wp-user-avatar'), |
| 98 | function () { |
| 99 | require dirname(__FILE__) . '/plans-page-sidebar.php'; |
| 100 | }, |
| 101 | 'ppmembershipplan', |
| 102 | 'sidebar' |
| 103 | ); |
| 104 | |
| 105 | add_meta_box( |
| 106 | 'ppress-subscription-plan-summary', |
| 107 | __('Summary', 'wp-user-avatar'), |
| 108 | function () { |
| 109 | ?> |
| 110 | <div class="ppress-subscription-plan-summary-content"> |
| 111 | </div> |
| 112 | <?php |
| 113 | }, |
| 114 | 'ppmembershipplan', |
| 115 | 'sidebar' |
| 116 | ); |
| 117 | |
| 118 | if ($plan_data->exists()) { |
| 119 | add_meta_box( |
| 120 | 'ppress-subscription-plan-links', |
| 121 | __('Order Links', 'wp-user-avatar'), |
| 122 | function () use ($plan_data) { |
| 123 | $checkout_url = $plan_data->get_checkout_url(); |
| 124 | ?> |
| 125 | <div class="ppress-subscription-plan-payment-links"> |
| 126 | <p> |
| 127 | <label><?php _e('Checkout link:', 'wp-user-avatar'); ?> |
| 128 | <input type="text" onfocus="this.select();" readonly="readonly" value="<?= esc_url($checkout_url) ?>"/> |
| 129 | </label> |
| 130 | </p> |
| 131 | </div> |
| 132 | <?php |
| 133 | }, |
| 134 | 'ppmembershipplan', |
| 135 | 'sidebar' |
| 136 | ); |
| 137 | } |
| 138 | }); |
| 139 | |
| 140 | do_action('add_meta_boxes', 'ppmembershipplan', new WP_Post(new stdClass())); |
| 141 | ?> |
| 142 | <div id="poststuff"> |
| 143 | <div id="post-body" class="metabox-holder columns-2"> |
| 144 | <div id="postbox-container-1" class="postbox-container"> |
| 145 | <?php do_meta_boxes('ppmembershipplan', 'sidebar', ''); ?> |
| 146 | </div> |
| 147 | <div id="postbox-container-2" class="postbox-container"> |
| 148 | <?php do_meta_boxes('ppmembershipplan', 'advanced', ''); ?> |
| 149 | </div> |
| 150 | </div> |
| 151 | <br class="clear"> |
| 152 | </div> |
| 153 | |
| 154 | <?php add_action('admin_footer', function () { ?> |
| 155 | <script type="text/javascript"> |
| 156 | (function ($) { |
| 157 | |
| 158 | $('#billing_frequency').on('change', function () { |
| 159 | |
| 160 | if ($(this).val() !== 'lifetime') { |
| 161 | |
| 162 | $('#field-role-signup_fee').show(); |
| 163 | $('#field-role-free_trial').show(); |
| 164 | |
| 165 | $('#field-role-subscription_length').show() |
| 166 | .find('.ppress-plan-control').change(); |
| 167 | } else { |
| 168 | $('#field-role-subscription_length').hide(); |
| 169 | $('#field-role-total_payments').hide(); |
| 170 | $('#field-role-signup_fee').hide(); |
| 171 | $('#field-role-free_trial').hide(); |
| 172 | } |
| 173 | }); |
| 174 | |
| 175 | $('#subscription_length').on('change', function () { |
| 176 | $('#field-role-total_payments').toggle($(this).val() === 'fixed'); |
| 177 | }); |
| 178 | |
| 179 | $('#billing_frequency').change(); |
| 180 | |
| 181 | $(window).on('load', function () { |
| 182 | var tmpl = wp.template('ppress-plan-summary'); |
| 183 | |
| 184 | $('.ppress-plan-control').on('change', function () { |
| 185 | $('#ppress-subscription-plan-summary .ppress-subscription-plan-summary-content').html( |
| 186 | tmpl({ |
| 187 | 'price': $('.form-field #price').val(), |
| 188 | 'billing_frequency': $('.form-field #billing_frequency').val(), |
| 189 | 'total_payments': $('.form-field #total_payments').val(), |
| 190 | 'signup_fee': $('.form-field #signup_fee').val(), |
| 191 | 'subscription_length': $('.form-field #subscription_length').val(), |
| 192 | 'free_trial': $('.form-field #free_trial').val(), |
| 193 | }) |
| 194 | ); |
| 195 | }).change(); |
| 196 | |
| 197 | }); |
| 198 | })(jQuery); |
| 199 | </script> |
| 200 | <?php |
| 201 | }); |