This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
/
my_account.php
executable file
·259 lines (235 loc) · 8.05 KB
/
my_account.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php
/**
* My Account shortcode
* DISCLAIMER
* Do not edit or add directly to this file if you wish to upgrade Jigoshop to newer
* versions in the future. If you wish to customise Jigoshop core for your needs,
* please use our GitHub repository to publish essential changes for consideration.
*
* @package Jigoshop
* @category Customer
* @author Jigoshop
* @copyright Copyright © 2011-2014 Jigoshop.
* @license GNU General Public License v3
*/
function get_jigoshop_my_account($attributes)
{
return jigoshop_shortcode_wrapper('jigoshop_my_account', $attributes);
}
function jigoshop_my_account($attributes)
{
global $current_user;
$options = Jigoshop_Base::get_options();
$attributes = shortcode_atts(array(
'recent_orders' => 5
), $attributes);
$recent_orders = ('all' == $attributes['recent_orders']) ? -1 : $attributes['recent_orders'];
get_currentuserinfo();
jigoshop_render('shortcode/my_account/my_account', array(
'current_user' => $current_user,
'options' => $options,
'recent_orders' => $recent_orders,
));
}
function get_jigoshop_edit_address()
{
return jigoshop_shortcode_wrapper('jigoshop_edit_address');
}
function jigoshop_get_address_to_edit()
{
$address = 'billing';
if (isset($_GET['address']) && in_array($_GET['address'], array('billing', 'shipping'))) {
$address = $_GET['address'];
}
return $address;
}
function jigoshop_get_address_fields($load_address, $user_id)
{
$address = array(
array(
'name' => $load_address.'_first_name',
'label' => __('First Name', 'jigoshop'),
'placeholder' => __('First Name', 'jigoshop'),
'required' => true,
'class' => array('form-row-first'),
'value' => get_user_meta($user_id, $load_address.'_first_name', true)
),
array(
'name' => $load_address.'_last_name',
'label' => __('Last Name', 'jigoshop'),
'placeholder' => __('Last Name', 'jigoshop'),
'required' => true,
'class' => array('form-row-last columned'),
'value' => get_user_meta($user_id, $load_address.'_last_name', true)
),
array(
'name' => $load_address.'_company',
'label' => __('Company', 'jigoshop'),
'placeholder' => __('Company', 'jigoshop'),
'class' => array('columned full-row clear'),
'value' => get_user_meta($user_id, $load_address.'_company_name', true)
),
array(
'name' => $load_address.'_euvatno',
'label' => __('EU VAT Number', 'jigoshop'),
'placeholder' => __('EU VAT Number', 'jigoshop'),
'class' => array('columned full-row clear'),
'value' => get_user_meta($user_id, $load_address.'_euvatno', true)
),
array(
'name' => $load_address.'_address_1',
'label' => __('Address', 'jigoshop'),
'placeholder' => __('Address 1', 'jigoshop'),
'required' => true,
'class' => array('form-row-first'),
'value' => get_user_meta($user_id, $load_address.'_address_1', true)
),
array(
'name' => $load_address.'_address_2',
'label' => __('Address 2', 'jigoshop'),
'placeholder' => __('Address 2', 'jigoshop'),
'class' => array('form-row-last'),
'label_class' => array('hidden'),
'value' => get_user_meta($user_id, $load_address.'_address_2', true)
),
array(
'name' => $load_address.'_city',
'label' => __('City', 'jigoshop'),
'placeholder' => __('City', 'jigoshop'),
'required' => true,
'class' => array('form-row-first'),
'value' => get_user_meta($user_id, $load_address.'_city', true)
),
array(
'type' => 'postcode',
'validate' => 'postcode',
'format' => 'postcode',
'name' => $load_address.'_postcode',
'label' => __('Postcode', 'jigoshop'),
'placeholder' => __('Postcode', 'jigoshop'),
'required' => true,
'class' => array('form-row-last'),
'value' => get_user_meta($user_id, $load_address.'_postcode', true)
),
array(
'type' => 'country',
'name' => $load_address.'_country',
'label' => __('Country', 'jigoshop'),
'required' => true,
'class' => array('form-row-first'),
'rel' => $load_address.'_state',
'value' => get_user_meta($user_id, $load_address.'_country', true)
),
array(
'type' => 'state',
'name' => $load_address.'_state',
'label' => __('State/Province', 'jigoshop'),
'required' => true,
'class' => array('form-row-last'),
'rel' => $load_address.'_country',
'value' => get_user_meta($user_id, $load_address.'_state', true)
),
array(
'name' => $load_address.'_email',
'validate' => 'email',
'label' => __('Email Address', 'jigoshop'),
'placeholder' => __('you@yourdomain.com', 'jigoshop'),
'required' => true,
'class' => array('form-row-first'),
'value' => get_user_meta($user_id, $load_address.'_email', true)
),
array(
'name' => $load_address.'_phone',
'validate' => 'phone',
'label' => __('Phone', 'jigoshop'),
'placeholder' => __('Phone number', 'jigoshop'),
'required' => true,
'class' => array('form-row-last'),
'value' => get_user_meta($user_id, $load_address.'_phone', true)
)
);
return apply_filters('jigoshop_customer_account_address_fields', $address);
}
function jigoshop_edit_address()
{
$account_url = get_permalink(jigoshop_get_page_id(JIGOSHOP_MY_ACCOUNT));
$user_id = get_current_user_id();
$load_address = jigoshop_get_address_to_edit();
$address = jigoshop_get_address_fields($load_address, $user_id);
if (isset($_POST['save_address']) && jigoshop::verify_nonce(JIGOSHOP_EDIT_ADDRESS)) {
if ($user_id > 0) {
foreach ($address as &$field) {
if (isset($_POST[$field['name']])) {
$field['value'] = jigowatt_clean($_POST[$field['name']]);
update_user_meta($user_id, $field['name'], $field['value']);
}
}
do_action('jigoshop_user_edit_address', $user_id, $address);
}
}
jigoshop_render('shortcode/my_account/edit_address', array(
'url' => add_query_arg('address', $load_address,
apply_filters('jigoshop_get_edit_address_page_id', get_permalink(jigoshop_get_page_id(JIGOSHOP_EDIT_ADDRESS)))),
'account_url' => $account_url,
'load_address' => $load_address,
'address' => $address,
));
}
function get_jigoshop_change_password()
{
return jigoshop_shortcode_wrapper('jigoshop_change_password');
}
function jigoshop_change_password()
{
jigoshop_render('shortcode/my_account/change_password', array());
}
function get_jigoshop_view_order()
{
return jigoshop_shortcode_wrapper('jigoshop_view_order');
}
function jigoshop_view_order()
{
$options = Jigoshop_Base::get_options();
$order = new jigoshop_order($_GET['order']);
jigoshop_render('shortcode/my_account/view_order', array(
'order' => $order,
'options' => $options,
));
}
add_action('template_redirect', function (){
$isViewOrder = is_jigoshop_single_page(JIGOSHOP_VIEW_ORDER);
$isEditAddress = is_jigoshop_single_page(JIGOSHOP_EDIT_ADDRESS);
$isChangePassword = is_jigoshop_single_page(JIGOSHOP_CHANGE_PASSWORD);
if (($isViewOrder || $isEditAddress || $isChangePassword) && !is_user_logged_in()) {
wp_safe_redirect(apply_filters('jigoshop_get_myaccount_page_id', get_permalink(jigoshop_get_page_id(JIGOSHOP_MY_ACCOUNT))));
exit;
}
if ($isViewOrder) {
if (!isset($_GET['order'])) {
wp_safe_redirect(apply_filters('jigoshop_get_myaccount_page_id', get_permalink(jigoshop_get_page_id('myaccount'))));
exit;
}
$order = new jigoshop_order($_GET['order']);
if ($order->user_id != get_current_user_id()) {
wp_safe_redirect(apply_filters('jigoshop_get_myaccount_page_id', get_permalink(jigoshop_get_page_id('myaccount'))));
exit;
}
}
if ($isChangePassword){
$user_id = get_current_user_id();
if ($_POST && $user_id > 0 && jigoshop::verify_nonce('change_password')) {
if ($_POST['password-1'] && $_POST['password-2']) {
if ($_POST['password-1'] == $_POST['password-2']) {
wp_update_user(array('ID' => $user_id, 'user_pass' => $_POST['password-1']));
jigoshop::add_message(__('Password changed successfully.', 'jigoshop'));
wp_safe_redirect(apply_filters('jigoshop_get_myaccount_page_id', get_permalink(jigoshop_get_page_id(JIGOSHOP_MY_ACCOUNT))));
exit;
} else {
jigoshop::add_error(__('Passwords do not match.', 'jigoshop'));
}
} else {
jigoshop::add_error(__('Please enter your password.', 'jigoshop'));
}
}
}
});