CouponsPage
1 year ago
CustomersPage
5 months ago
DashboardPage
1 year ago
DownloadLogsPage
1 year ago
ExportPage
5 months ago
GroupsPage
1 year ago
OrdersPage
1 year ago
PlansPage
2 months ago
SubscriptionsPage
3 months ago
TaxSettings
3 years ago
views
1 month ago
CheckListHeader.php
3 years ago
CheckoutFieldsManager.php
1 year ago
ContextualStateChangeHelper.php
3 years ago
FileDownloads.php
3 years ago
PaymentMethods.php
1 year ago
PaymentSettings.php
1 month ago
PlanIntegrationsMetabox.php
10 months ago
SettingsFieldsParser.php
1 year ago
index.php
3 years ago
ContextualStateChangeHelper.php
58 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Admin\SettingsPages\Membership; |
| 4 | |
| 5 | class ContextualStateChangeHelper |
| 6 | { |
| 7 | public static function init() |
| 8 | { |
| 9 | add_action('admin_footer', [__CLASS__, 'css_js_script']); |
| 10 | } |
| 11 | |
| 12 | public static function css_js_script() |
| 13 | { |
| 14 | ?> |
| 15 | <script type="text/html" id="tmpl-ppress-billing-state-input"> |
| 16 | <input name="ppress_billing_state" type="text" id="ppress_billing_state" value=""> |
| 17 | </script> |
| 18 | |
| 19 | <script type="text/html" id="tmpl-ppress-billing-state-select"> |
| 20 | <select name="ppress_billing_state" id="ppress_billing_state"> |
| 21 | <option value="">———</option> |
| 22 | <# jQuery.each(data.options, function(index, value) { #> |
| 23 | <option value="{{index}}">{{value}}</option> |
| 24 | <# }); #> |
| 25 | </select> |
| 26 | </script> |
| 27 | |
| 28 | <script type="text/javascript"> |
| 29 | (function ($) { |
| 30 | $(function () { |
| 31 | |
| 32 | var ppress_countries_states = <?php echo wp_json_encode(array_filter(ppress_array_of_world_states())); ?>, |
| 33 | country_state_select_tmpl = wp.template('ppress-billing-state-select'), |
| 34 | country_state_input_tmpl = wp.template('ppress-billing-state-input'); |
| 35 | |
| 36 | $(document).on('change', '#ppress_billing_country', function () { |
| 37 | |
| 38 | var val = $(this).val(), field; |
| 39 | |
| 40 | if (val in ppress_countries_states) { |
| 41 | |
| 42 | field = country_state_select_tmpl({ |
| 43 | options: ppress_countries_states[val] |
| 44 | }); |
| 45 | |
| 46 | } else { |
| 47 | |
| 48 | field = country_state_input_tmpl(); |
| 49 | } |
| 50 | |
| 51 | $('#ppress_billing_state').replaceWith(field); |
| 52 | }); |
| 53 | }) |
| 54 | })(jQuery); |
| 55 | </script> |
| 56 | <?php |
| 57 | } |
| 58 | } |