MyAccountTag.php
1 month ago
account-settings.tmpl.php
3 years ago
billing-details.tmpl.php
1 year ago
change-password.tmpl.php
1 year ago
dashboard.tmpl.php
3 years ago
delete-account.tmpl.php
1 year ago
downloads.tmpl.php
1 year ago
edit-profile.tmpl.php
1 year ago
email-notifications.tmpl.php
3 years ago
index.php
5 years ago
orders.tmpl.php
3 years ago
subscriptions.tmpl.php
1 year ago
view-order.tmpl.php
1 year ago
view-subscription.tmpl.php
1 year ago
billing-details.tmpl.php
147 lines
| 1 | <?php |
| 2 | |
| 3 | use ProfilePress\Core\Admin\ProfileCustomFields; |
| 4 | use ProfilePress\Core\Classes\EditUserProfile; |
| 5 | use ProfilePress\Core\Membership\CheckoutFields; |
| 6 | |
| 7 | if ( ! defined('ABSPATH')) { |
| 8 | exit; // Exit if accessed directly |
| 9 | } |
| 10 | |
| 11 | $billing_details_fields = CheckoutFields::standard_billing_fields(); |
| 12 | |
| 13 | $success_message = EditUserProfile::get_success_message(); |
| 14 | |
| 15 | echo '<div class="profilepress-myaccount-edit-profile">'; |
| 16 | |
| 17 | echo '<h2>' . esc_html__('Billing Address', 'wp-user-avatar') . '</h2>'; |
| 18 | |
| 19 | if (isset($_GET['edit']) && $_GET['edit'] == 'true') : |
| 20 | echo $success_message; |
| 21 | endif; |
| 22 | |
| 23 | if ( ! empty($this->edit_profile_form_error)) : |
| 24 | |
| 25 | if (strpos($this->edit_profile_form_error, 'profilepress-edit-profile-status') !== false) : |
| 26 | echo $this->edit_profile_form_error; |
| 27 | else : |
| 28 | echo '<div class="profilepress-edit-profile-status">'; |
| 29 | echo $this->edit_profile_form_error; |
| 30 | echo '</div>'; |
| 31 | endif; |
| 32 | endif; |
| 33 | |
| 34 | ob_start(); |
| 35 | echo '[pp-edit-profile-form]'; |
| 36 | |
| 37 | echo '<div class="profilepress-myaccount-form-wrap">'; |
| 38 | |
| 39 | printf( |
| 40 | '<p>%s</p>', |
| 41 | apply_filters( |
| 42 | 'ppress_myaccount_billing_details_description', |
| 43 | esc_html__('The following billing address will be used on the checkout page by default.', 'wp-user-avatar')) |
| 44 | ); |
| 45 | |
| 46 | $billing_details_fields = apply_filters('ppress_myaccount_billing_details_fields', $billing_details_fields); |
| 47 | |
| 48 | if (is_array($billing_details_fields) && ! empty($billing_details_fields)) : |
| 49 | |
| 50 | foreach ($billing_details_fields as $field_key => $field) : |
| 51 | |
| 52 | $field_type = $field['field_type']; |
| 53 | |
| 54 | $options = ''; |
| 55 | |
| 56 | if ($field_key == CheckoutFields::BILLING_STATE) { |
| 57 | |
| 58 | $billing_country = get_user_meta(get_current_user_id(), CheckoutFields::BILLING_COUNTRY, true); |
| 59 | $billing_country_states = ! empty($billing_country) ? ppress_array_of_world_states($billing_country) : []; |
| 60 | |
| 61 | if ( ! empty($billing_country_states)) { |
| 62 | $field_type = 'select'; |
| 63 | $options = base64_encode(serialize(['' => '————'] + $billing_country_states)); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | if (apply_filters('ppress_myaccount_billing_details_disable_' . $field_key, false)) continue; |
| 68 | |
| 69 | // skip woocommerce core billing / shipping fields added to wordpress profile admin page. |
| 70 | if (in_array($field_key, ppress_woocommerce_billing_shipping_fields())) continue; |
| 71 | |
| 72 | echo '<div class="profilepress-myaccount-form-field">'; |
| 73 | |
| 74 | if ($field_type !== 'agreeable') { |
| 75 | printf('<label for="%s">%s</label>', $field_key, $field['label']); |
| 76 | } |
| 77 | |
| 78 | echo sprintf( |
| 79 | '[edit-profile-cpf id="%1$s" key="%1$s" type="%2$s" key_value_options="%3$s" class="profilepress-myaccount-form-control"]', |
| 80 | $field_key, $field_type, $options |
| 81 | ); |
| 82 | echo '</div>'; |
| 83 | |
| 84 | endforeach; |
| 85 | |
| 86 | endif; |
| 87 | |
| 88 | echo '<div class="profilepress-myaccount-form-field">'; |
| 89 | echo '[edit-profile-submit]'; |
| 90 | echo '</div>'; |
| 91 | echo '</div>'; |
| 92 | |
| 93 | echo '<input type="hidden" name="ppmyac_form_action" value="updateProfile">'; |
| 94 | |
| 95 | echo '[/pp-edit-profile-form]'; |
| 96 | |
| 97 | echo do_shortcode(ob_get_clean(), true); |
| 98 | echo '</div>'; |
| 99 | |
| 100 | do_action('ppress_myaccount_billing_details'); |
| 101 | |
| 102 | add_action('wp_footer', function () { |
| 103 | ?> |
| 104 | <script type="text/html" id="tmpl-ppress-profile-state-input"> |
| 105 | <input name="ppress_billing_state" type="text" id="ppress_billing_state" class="profilepress-myaccount-form-control" value=""> |
| 106 | </script> |
| 107 | |
| 108 | <script type="text/html" id="tmpl-ppress-profile-state-select"> |
| 109 | <select name="ppress_billing_state" id="ppress_billing_state" class="profilepress-myaccount-form-control"> |
| 110 | <option value="">———</option> |
| 111 | <# jQuery.each(data.options, function(index, value) { #> |
| 112 | <option value="{{index}}">{{value}}</option> |
| 113 | <# }); #> |
| 114 | </select> |
| 115 | </script> |
| 116 | |
| 117 | <script type="text/javascript"> |
| 118 | (function ($) { |
| 119 | $(function () { |
| 120 | |
| 121 | var ppress_countries_states = <?php echo wp_json_encode(array_filter(ppress_array_of_world_states())); ?>, |
| 122 | country_state_select_tmpl = wp.template('ppress-profile-state-select'), |
| 123 | country_state_input_tmpl = wp.template('ppress-profile-state-input'); |
| 124 | |
| 125 | $(document).on('change', '#ppress_billing_country', function () { |
| 126 | |
| 127 | var val = $(this).val(), field; |
| 128 | |
| 129 | if (val in ppress_countries_states) { |
| 130 | |
| 131 | field = country_state_select_tmpl({ |
| 132 | options: ppress_countries_states[val] |
| 133 | }); |
| 134 | |
| 135 | } else { |
| 136 | |
| 137 | field = country_state_input_tmpl(); |
| 138 | } |
| 139 | |
| 140 | $('#ppress_billing_state').replaceWith(field); |
| 141 | }); |
| 142 | }) |
| 143 | })(jQuery); |
| 144 | </script> |
| 145 | <?php |
| 146 | }); |
| 147 |