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-plan-group.php
131 lines
| 1 | <?php |
| 2 | |
| 3 | use ProfilePress\Core\Admin\SettingsPages\Membership\SettingsFieldsParser; |
| 4 | use ProfilePress\Core\Membership\Models\Group\GroupFactory; |
| 5 | use ProfilePress\Core\Membership\Repositories\PlanRepository; |
| 6 | |
| 7 | $group_details = [ |
| 8 | [ |
| 9 | 'id' => 'name', |
| 10 | 'type' => 'text', |
| 11 | 'label' => esc_html__('Group Name', 'wp-user-avatar'), |
| 12 | ], |
| 13 | [ |
| 14 | 'id' => 'plan_ids', |
| 15 | 'type' => 'select2', |
| 16 | 'label' => esc_html__('Membership Plans', 'wp-user-avatar'), |
| 17 | 'options' => (function () { |
| 18 | $bucket = []; |
| 19 | foreach (PlanRepository::init()->retrieveAll() as $plan) { |
| 20 | $bucket[$plan->get_id()] = $plan->get_name(); |
| 21 | } |
| 22 | |
| 23 | return $bucket; |
| 24 | })(), |
| 25 | 'description' => esc_html__('Select membership plans to add to this group so customers can switch between the plans.', 'wp-user-avatar') |
| 26 | ], |
| 27 | [ |
| 28 | 'id' => 'plans_display_field', |
| 29 | 'type' => 'select', |
| 30 | 'label' => esc_html__('Plans Checkout Display', 'wp-user-avatar'), |
| 31 | 'options' => [ |
| 32 | 'radio' => esc_html__('Radio Buttons', 'wp-user-avatar'), |
| 33 | 'select' => esc_html__('Select Dropdown', 'wp-user-avatar'), |
| 34 | ], |
| 35 | 'description' => esc_html__('Select how you want to display the membership plans for selection on the Group checkout page.', 'wp-user-avatar') |
| 36 | ] |
| 37 | ]; |
| 38 | |
| 39 | $group_data = GroupFactory::fromId(absint(ppressGET_var('id'))); |
| 40 | |
| 41 | if (ppressGET_var('ppress_group_action') == 'edit' && ! $group_data->exists()) { |
| 42 | ppress_content_http_redirect(PPRESS_MEMBERSHIP_GROUPS_SETTINGS_PAGE); |
| 43 | |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | add_action('add_meta_boxes', function () use ($group_details, $group_data) { |
| 48 | |
| 49 | add_meta_box( |
| 50 | 'ppress-membership-group-content', |
| 51 | esc_html__('Group Details', 'wp-user-avatar'), |
| 52 | function () use ($group_details, $group_data) { |
| 53 | echo '<div class="ppress-membership-group-details">'; |
| 54 | (new SettingsFieldsParser($group_details, $group_data, 'ppress-group-control'))->build(); |
| 55 | echo '</div>'; |
| 56 | }, |
| 57 | 'ppmembershipgroup' |
| 58 | ); |
| 59 | |
| 60 | add_meta_box( |
| 61 | 'submitdiv', |
| 62 | __('Publish', 'wp-user-avatar'), |
| 63 | function () { |
| 64 | require dirname(__FILE__) . '/groups-page-sidebar.php'; |
| 65 | }, |
| 66 | 'ppmembershipgroup', |
| 67 | 'sidebar' |
| 68 | ); |
| 69 | |
| 70 | |
| 71 | if ($group_data->exists()) { |
| 72 | add_meta_box( |
| 73 | 'ppress-plan-group-checkout-url', |
| 74 | __('Checkout URL', 'wp-user-avatar'), |
| 75 | function () use ($group_data) { |
| 76 | ?> |
| 77 | <div class="ppress-subscription-plan-payment-links"> |
| 78 | <p> |
| 79 | <input type="text" id="ppress-group-checkout-url" onfocus="this.select();" readonly="readonly" value="<?= esc_url($group_data->get_checkout_url()) ?>" style="width: 100%;"/> |
| 80 | </p> |
| 81 | <p style="display: flex; align-items: center; gap: 10px;"> |
| 82 | <button type="button" class="button" id="ppress-copy-url-btn"><?php esc_html_e('Copy URL', 'wp-user-avatar'); ?></button> |
| 83 | <span id="ppress-copy-msg" style="color: green; display: none;"></span> |
| 84 | </p> |
| 85 | </div> |
| 86 | <?php |
| 87 | }, |
| 88 | 'ppmembershipgroup', |
| 89 | 'sidebar' |
| 90 | ); |
| 91 | } |
| 92 | |
| 93 | }); |
| 94 | |
| 95 | do_action('add_meta_boxes', 'ppmembershipgroup', new WP_Post(new stdClass())); |
| 96 | ?> |
| 97 | <div id="poststuff"> |
| 98 | <div id="post-body" class="metabox-holder columns-2"> |
| 99 | |
| 100 | <div id="postbox-container-1" class="postbox-container"> |
| 101 | <?php do_meta_boxes('ppmembershipgroup', 'sidebar', ''); ?> |
| 102 | </div> |
| 103 | <div id="postbox-container-2" class="postbox-container"> |
| 104 | <?php do_meta_boxes('ppmembershipgroup', 'advanced', ''); ?> |
| 105 | </div> |
| 106 | </div> |
| 107 | <br class="clear"> |
| 108 | </div> |
| 109 | |
| 110 | <?php add_action('admin_footer', function () { ?> |
| 111 | <script type="text/javascript"> |
| 112 | (function ($) { |
| 113 | |
| 114 | $('#ppress-copy-url-btn').on('click', function () { |
| 115 | var input = $('#ppress-group-checkout-url')[0]; |
| 116 | var msg = $('#ppress-copy-msg'); |
| 117 | |
| 118 | input.select(); |
| 119 | input.setSelectionRange(0, 99999); // For mobile |
| 120 | |
| 121 | document.execCommand('copy'); |
| 122 | msg.text('<?php esc_html_e("Copied!", "wp-user-avatar");?>') |
| 123 | .css('color', 'green') |
| 124 | .show() |
| 125 | .fadeOut(3000); |
| 126 | }); |
| 127 | |
| 128 | })(jQuery); |
| 129 | </script> |
| 130 | <?php |
| 131 | }); |