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.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / templates / dashboard / account / settings / withdraw.php
tutor / templates / dashboard / account / settings Last commit date
account.php 4 days ago header.php 4 days ago preferences.php 4 days ago reset-password-modal.php 4 days ago security.php 4 days ago social-accounts.php 4 days ago withdraw.php 4 days ago
withdraw.php
187 lines
1 <?php
2 /**
3 * Withdrawal Method Settings
4 *
5 * @package Tutor\Templates
6 * @author Themeum <support@themeum.com>
7 * @link https://themeum.com
8 * @since 4.0.0
9 */
10
11 defined( 'ABSPATH' ) || exit;
12
13 use Tutor\Models\WithdrawModel;
14 use Tutor\Components\EmptyState;
15 use Tutor\Components\InputField;
16 use Tutor\Components\Constants\InputType;
17
18 $get_field_key = fn( $method_id, $field_name ) => $method_id . '_' . $field_name;
19
20 $map_field_type = function ( $field_type ) {
21 $types = array(
22 'email' => InputType::EMAIL,
23 'number' => InputType::NUMBER,
24 'textarea' => InputType::TEXTAREA,
25 );
26 return isset( $types[ $field_type ] ) ? $types[ $field_type ] : InputType::TEXT;
27 };
28
29 $get_saved_method_values = function ( $method_id, $user_id ) {
30 $meta_key = '_tutor_withdraw_method_data_' . $method_id;
31 $values = get_user_meta( $user_id, $meta_key, true );
32 $values = maybe_unserialize( $values );
33 return is_array( $values ) ? $values : array();
34 };
35
36 $get_field_value = function ( $method_id, $field_name, $old_method_key, $saved_account, $method_values ) {
37 $saved_value = '';
38
39 if ( $old_method_key === $method_id ) {
40 $saved_value = tutor_utils()->avalue_dot( $field_name . '.value', $saved_account );
41 }
42
43 if ( ! $saved_value && isset( $method_values[ $field_name ]['value'] ) ) {
44 $saved_value = $method_values[ $field_name ]['value'];
45 }
46
47 return $saved_value ? $saved_value : '';
48 };
49
50 $user_id = get_current_user_id();
51 $withdrawal_methods = apply_filters( 'tutor_withdrawal_methods_available', array() );
52 $saved_account = WithdrawModel::get_user_withdraw_method();
53
54 if ( empty( $withdrawal_methods ) ) {
55 ?>
56 <section class="tutor-flex tutor-flex-column tutor-gap-4">
57 <h5 class="tutor-h5 tutor-md-hidden tutor-my-none"><?php echo esc_html__( 'Withdrawal Method', 'tutor' ); ?></h5>
58 <?php
59 EmptyState::make()
60 ->title( __( "There's no Withdrawal method selected yet! To select a Withdraw method, please contact the Site Admin.", 'tutor' ) )
61 ->render();
62 ?>
63 </section>
64 <?php
65 return;
66 }
67
68 $method_options = array_map(
69 fn( $method_id, $method ) => array(
70 'label' => tutor_utils()->avalue_dot( 'method_name', $method ),
71 'value' => $method_id,
72 ),
73 array_keys( $withdrawal_methods ),
74 $withdrawal_methods
75 );
76
77 $old_method_key = tutor_utils()->avalue_dot( 'withdraw_method_key', $saved_account );
78 $default_values = array( 'withdraw_method' => $old_method_key ? $old_method_key : '' );
79
80 do_action( 'tutor_withdraw_set_account_form_before' );
81
82 foreach ( $withdrawal_methods as $method_id => $method ) {
83 $method_values = $get_saved_method_values( $method_id, $user_id );
84 $form_fields = tutor_utils()->avalue_dot( 'form_fields', $method );
85
86 if ( is_array( $form_fields ) ) {
87 foreach ( $form_fields as $field_name => $field ) {
88 $field_key = $get_field_key( $method_id, $field_name );
89 $default_values[ $field_key ] = $get_field_value(
90 $method_id,
91 $field_name,
92 $old_method_key,
93 $saved_account,
94 $method_values
95 );
96 }
97 }
98 }
99
100 ?>
101
102 <section class="tutor-flex tutor-flex-column tutor-gap-4">
103 <h5 class="tutor-h5 tutor-md-hidden tutor-my-none"><?php echo esc_html__( 'Withdrawal Method', 'tutor' ); ?></h5>
104
105 <form
106 id="<?php echo esc_attr( $form_id ); ?>"
107 x-data='tutorForm({
108 id: "<?php echo esc_attr( $form_id ); ?>",
109 mode: "onChange",
110 defaultValues: <?php echo wp_json_encode( $default_values ); ?>,
111 })'
112 x-bind="getFormBindings()"
113 @submit="handleSubmit((data) => handleSaveWithdrawMethod(data, '<?php echo esc_attr( $form_id ); ?>'))($event)"
114 class="tutor-card tutor-card-rounded-2xl tutor-flex tutor-flex-column tutor-gap-5"
115 >
116 <?php
117 $min_withdraw_amount = tutor_utils()->get_option( 'min_withdraw_amount' );
118 $formatted_min = tutor_utils()->tutor_price( $min_withdraw_amount );
119
120 InputField::make()
121 ->type( InputType::SELECT )
122 ->label( __( 'Select Method', 'tutor' ) )
123 ->name( 'withdraw_method' )
124 ->id( 'withdraw_method' )
125 ->options( $method_options )
126 ->placeholder( __( 'Select a withdrawal method', 'tutor' ) )
127 ->required()
128 ->attr( 'x-bind', "register('withdraw_method', { required: true })" )
129 ->help_text(
130 sprintf(
131 /* translators: %s: minimum withdraw amount */
132 __( 'Minimum withdraw amount is %s', 'tutor' ),
133 $formatted_min
134 ),
135 tutor_price_allowed_html()
136 )
137 ->render();
138 ?>
139
140 <?php foreach ( $withdrawal_methods as $method_id => $method ) : ?>
141 <?php
142 do_action( "tutor_withdraw_set_account_{$method_id}_before" );
143
144 $form_fields = tutor_utils()->avalue_dot( 'form_fields', $method );
145 if ( ! is_array( $form_fields ) || empty( $form_fields ) ) {
146 continue;
147 }
148 ?>
149 <div
150 x-show="values.withdraw_method === '<?php echo esc_js( $method_id ); ?>'"
151 x-cloak
152 class="tutor-flex tutor-flex-column tutor-gap-5"
153 >
154 <?php foreach ( $form_fields as $field_name => $field ) : ?>
155 <?php
156 $field_key = $get_field_key( $method_id, $field_name );
157 $input_type = $map_field_type( $field['type'] ?? 'text' );
158 $register_options = 'number' === $input_type
159 ? '{ numberOnly: true }'
160 : '{}';
161
162 $input_field = InputField::make()
163 ->type( $input_type )
164 ->name( $field_key )
165 ->id( $field_key )
166 ->attr( 'x-bind', "register('{$field_key}', {$register_options})" );
167
168 if ( ! empty( $field['label'] ) ) {
169 $input_field->label( $field['label'] );
170 }
171
172 if ( ! empty( $field['desc'] ) ) {
173 $input_field->help_text( $field['desc'] );
174 }
175
176 $input_field->render();
177 ?>
178 <?php endforeach; ?>
179 </div>
180
181 <?php do_action( "tutor_withdraw_set_account_{$method_id}_after" ); ?>
182 <?php endforeach; ?>
183
184 <?php do_action( 'tutor_withdraw_set_account_form_after' ); ?>
185 </form>
186 </section>
187