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0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / wc-account-functions.php
woocommerce / includes Last commit date
abstracts 5 years ago admin 5 years ago cli 5 years ago customizer 5 years ago data-stores 4 years ago emails 5 years ago export 5 years ago gateways 5 years ago import 5 years ago integrations 5 years ago interfaces 5 years ago legacy 5 years ago libraries 5 years ago log-handlers 5 years ago payment-tokens 5 years ago queue 5 years ago shipping 5 years ago shortcodes 5 years ago theme-support 5 years ago tracks 5 years ago traits 5 years ago walkers 5 years ago wccom-site 5 years ago widgets 5 years ago class-wc-ajax.php 5 years ago class-wc-api.php 5 years ago class-wc-auth.php 5 years ago class-wc-autoloader.php 5 years ago class-wc-background-emailer.php 5 years ago class-wc-background-updater.php 5 years ago class-wc-breadcrumb.php 5 years ago class-wc-cache-helper.php 5 years ago class-wc-cart-fees.php 5 years ago class-wc-cart-session.php 5 years ago class-wc-cart-totals.php 5 years ago class-wc-cart.php 5 years ago class-wc-checkout.php 5 years ago class-wc-cli.php 5 years ago class-wc-comments.php 5 years ago class-wc-countries.php 5 years ago class-wc-coupon.php 5 years ago class-wc-customer-download-log.php 5 years ago class-wc-customer-download.php 5 years ago class-wc-customer.php 5 years ago class-wc-data-exception.php 5 years ago class-wc-data-store.php 5 years ago class-wc-datetime.php 5 years ago class-wc-deprecated-action-hooks.php 5 years ago class-wc-deprecated-filter-hooks.php 5 years ago class-wc-discounts.php 5 years ago class-wc-download-handler.php 5 years ago class-wc-emails.php 5 years ago class-wc-embed.php 5 years ago class-wc-form-handler.php 5 years ago class-wc-frontend-scripts.php 5 years ago class-wc-geo-ip.php 5 years ago class-wc-geolite-integration.php 5 years ago class-wc-geolocation.php 5 years ago class-wc-https.php 5 years ago class-wc-install.php 4 years ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 5 years ago class-wc-logger.php 5 years ago class-wc-meta-data.php 5 years ago class-wc-order-factory.php 5 years ago class-wc-order-item-coupon.php 5 years ago class-wc-order-item-fee.php 5 years ago class-wc-order-item-meta.php 5 years ago class-wc-order-item-product.php 5 years ago class-wc-order-item-shipping.php 5 years ago class-wc-order-item-tax.php 5 years ago class-wc-order-item.php 5 years ago class-wc-order-query.php 5 years ago class-wc-order-refund.php 5 years ago class-wc-order.php 5 years ago class-wc-payment-gateways.php 5 years ago class-wc-payment-tokens.php 5 years ago class-wc-post-data.php 5 years ago class-wc-post-types.php 5 years ago class-wc-privacy-background-process.php 5 years ago class-wc-privacy-erasers.php 5 years ago class-wc-privacy-exporters.php 5 years ago class-wc-privacy.php 5 years ago class-wc-product-attribute.php 5 years ago class-wc-product-download.php 5 years ago class-wc-product-external.php 5 years ago class-wc-product-factory.php 5 years ago class-wc-product-grouped.php 5 years ago class-wc-product-query.php 5 years ago class-wc-product-simple.php 5 years ago class-wc-product-variable.php 5 years ago class-wc-product-variation.php 5 years ago class-wc-query.php 5 years ago class-wc-rate-limiter.php 5 years ago class-wc-regenerate-images-request.php 5 years ago class-wc-regenerate-images.php 5 years ago class-wc-register-wp-admin-settings.php 5 years ago class-wc-rest-authentication.php 5 years ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 5 years ago class-wc-shipping-rate.php 5 years ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 5 years ago class-wc-shipping.php 5 years ago class-wc-shortcodes.php 5 years ago class-wc-structured-data.php 5 years ago class-wc-tax.php 5 years ago class-wc-template-loader.php 5 years ago class-wc-tracker.php 5 years ago class-wc-validation.php 5 years ago class-wc-webhook.php 5 years ago class-woocommerce.php 4 years ago wc-account-functions.php 5 years ago wc-attribute-functions.php 5 years ago wc-cart-functions.php 5 years ago wc-conditional-functions.php 5 years ago wc-core-functions.php 5 years ago wc-coupon-functions.php 5 years ago wc-deprecated-functions.php 5 years ago wc-formatting-functions.php 5 years ago wc-notice-functions.php 5 years ago wc-order-functions.php 5 years ago wc-order-item-functions.php 5 years ago wc-page-functions.php 5 years ago wc-product-functions.php 5 years ago wc-rest-functions.php 5 years ago wc-stock-functions.php 5 years ago wc-template-functions.php 5 years ago wc-template-hooks.php 5 years ago wc-term-functions.php 5 years ago wc-update-functions.php 4 years ago wc-user-functions.php 5 years ago wc-webhook-functions.php 5 years ago wc-widget-functions.php 5 years ago
wc-account-functions.php
423 lines
1 <?php
2 /**
3 * WooCommerce Account Functions
4 *
5 * Functions for account specific things.
6 *
7 * @package WooCommerce/Functions
8 * @version 2.6.0
9 */
10
11 defined( 'ABSPATH' ) || exit;
12
13 /**
14 * Returns the url to the lost password endpoint url.
15 *
16 * @param string $default_url Default lost password URL.
17 * @return string
18 */
19 function wc_lostpassword_url( $default_url = '' ) {
20 // Avoid loading too early.
21 if ( ! did_action( 'init' ) ) {
22 return $default_url;
23 }
24
25 // Don't redirect to the woocommerce endpoint on global network admin lost passwords.
26 if ( is_multisite() && isset( $_GET['redirect_to'] ) && false !== strpos( wp_unslash( $_GET['redirect_to'] ), network_admin_url() ) ) { // WPCS: input var ok, sanitization ok, CSRF ok.
27 return $default_url;
28 }
29
30 $wc_account_page_url = wc_get_page_permalink( 'myaccount' );
31 $wc_account_page_exists = wc_get_page_id( 'myaccount' ) > 0;
32 $lost_password_endpoint = get_option( 'woocommerce_myaccount_lost_password_endpoint' );
33
34 if ( $wc_account_page_exists && ! empty( $lost_password_endpoint ) ) {
35 return wc_get_endpoint_url( $lost_password_endpoint, '', $wc_account_page_url );
36 } else {
37 return $default_url;
38 }
39 }
40
41 add_filter( 'lostpassword_url', 'wc_lostpassword_url', 10, 1 );
42
43 /**
44 * Get the link to the edit account details page.
45 *
46 * @return string
47 */
48 function wc_customer_edit_account_url() {
49 $edit_account_url = wc_get_endpoint_url( 'edit-account', '', wc_get_page_permalink( 'myaccount' ) );
50
51 return apply_filters( 'woocommerce_customer_edit_account_url', $edit_account_url );
52 }
53
54 /**
55 * Get the edit address slug translation.
56 *
57 * @param string $id Address ID.
58 * @param bool $flip Flip the array to make it possible to retrieve the values ​​from both sides.
59 *
60 * @return string Address slug i18n.
61 */
62 function wc_edit_address_i18n( $id, $flip = false ) {
63 $slugs = apply_filters(
64 'woocommerce_edit_address_slugs',
65 array(
66 'billing' => sanitize_title( _x( 'billing', 'edit-address-slug', 'woocommerce' ) ),
67 'shipping' => sanitize_title( _x( 'shipping', 'edit-address-slug', 'woocommerce' ) ),
68 )
69 );
70
71 if ( $flip ) {
72 $slugs = array_flip( $slugs );
73 }
74
75 if ( ! isset( $slugs[ $id ] ) ) {
76 return $id;
77 }
78
79 return $slugs[ $id ];
80 }
81
82 /**
83 * Get My Account menu items.
84 *
85 * @since 2.6.0
86 * @return array
87 */
88 function wc_get_account_menu_items() {
89 $endpoints = array(
90 'orders' => get_option( 'woocommerce_myaccount_orders_endpoint', 'orders' ),
91 'downloads' => get_option( 'woocommerce_myaccount_downloads_endpoint', 'downloads' ),
92 'edit-address' => get_option( 'woocommerce_myaccount_edit_address_endpoint', 'edit-address' ),
93 'payment-methods' => get_option( 'woocommerce_myaccount_payment_methods_endpoint', 'payment-methods' ),
94 'edit-account' => get_option( 'woocommerce_myaccount_edit_account_endpoint', 'edit-account' ),
95 'customer-logout' => get_option( 'woocommerce_logout_endpoint', 'customer-logout' ),
96 );
97
98 $items = array(
99 'dashboard' => __( 'Dashboard', 'woocommerce' ),
100 'orders' => __( 'Orders', 'woocommerce' ),
101 'downloads' => __( 'Downloads', 'woocommerce' ),
102 'edit-address' => __( 'Addresses', 'woocommerce' ),
103 'payment-methods' => __( 'Payment methods', 'woocommerce' ),
104 'edit-account' => __( 'Account details', 'woocommerce' ),
105 'customer-logout' => __( 'Logout', 'woocommerce' ),
106 );
107
108 // Remove missing endpoints.
109 foreach ( $endpoints as $endpoint_id => $endpoint ) {
110 if ( empty( $endpoint ) ) {
111 unset( $items[ $endpoint_id ] );
112 }
113 }
114
115 // Check if payment gateways support add new payment methods.
116 if ( isset( $items['payment-methods'] ) ) {
117 $support_payment_methods = false;
118 foreach ( WC()->payment_gateways->get_available_payment_gateways() as $gateway ) {
119 if ( $gateway->supports( 'add_payment_method' ) || $gateway->supports( 'tokenization' ) ) {
120 $support_payment_methods = true;
121 break;
122 }
123 }
124
125 if ( ! $support_payment_methods ) {
126 unset( $items['payment-methods'] );
127 }
128 }
129
130 return apply_filters( 'woocommerce_account_menu_items', $items, $endpoints );
131 }
132
133 /**
134 * Get account menu item classes.
135 *
136 * @since 2.6.0
137 * @param string $endpoint Endpoint.
138 * @return string
139 */
140 function wc_get_account_menu_item_classes( $endpoint ) {
141 global $wp;
142
143 $classes = array(
144 'woocommerce-MyAccount-navigation-link',
145 'woocommerce-MyAccount-navigation-link--' . $endpoint,
146 );
147
148 // Set current item class.
149 $current = isset( $wp->query_vars[ $endpoint ] );
150 if ( 'dashboard' === $endpoint && ( isset( $wp->query_vars['page'] ) || empty( $wp->query_vars ) ) ) {
151 $current = true; // Dashboard is not an endpoint, so needs a custom check.
152 } elseif ( 'orders' === $endpoint && isset( $wp->query_vars['view-order'] ) ) {
153 $current = true; // When looking at individual order, highlight Orders list item (to signify where in the menu the user currently is).
154 } elseif ( 'payment-methods' === $endpoint && isset( $wp->query_vars['add-payment-method'] ) ) {
155 $current = true;
156 }
157
158 if ( $current ) {
159 $classes[] = 'is-active';
160 }
161
162 $classes = apply_filters( 'woocommerce_account_menu_item_classes', $classes, $endpoint );
163
164 return implode( ' ', array_map( 'sanitize_html_class', $classes ) );
165 }
166
167 /**
168 * Get account endpoint URL.
169 *
170 * @since 2.6.0
171 * @param string $endpoint Endpoint.
172 * @return string
173 */
174 function wc_get_account_endpoint_url( $endpoint ) {
175 if ( 'dashboard' === $endpoint ) {
176 return wc_get_page_permalink( 'myaccount' );
177 }
178
179 if ( 'customer-logout' === $endpoint ) {
180 return wc_logout_url();
181 }
182
183 return wc_get_endpoint_url( $endpoint, '', wc_get_page_permalink( 'myaccount' ) );
184 }
185
186 /**
187 * Get My Account > Orders columns.
188 *
189 * @since 2.6.0
190 * @return array
191 */
192 function wc_get_account_orders_columns() {
193 $columns = apply_filters(
194 'woocommerce_account_orders_columns',
195 array(
196 'order-number' => __( 'Order', 'woocommerce' ),
197 'order-date' => __( 'Date', 'woocommerce' ),
198 'order-status' => __( 'Status', 'woocommerce' ),
199 'order-total' => __( 'Total', 'woocommerce' ),
200 'order-actions' => __( 'Actions', 'woocommerce' ),
201 )
202 );
203
204 // Deprecated filter since 2.6.0.
205 return apply_filters( 'woocommerce_my_account_my_orders_columns', $columns );
206 }
207
208 /**
209 * Get My Account > Downloads columns.
210 *
211 * @since 2.6.0
212 * @return array
213 */
214 function wc_get_account_downloads_columns() {
215 $columns = apply_filters(
216 'woocommerce_account_downloads_columns',
217 array(
218 'download-product' => __( 'Product', 'woocommerce' ),
219 'download-remaining' => __( 'Downloads remaining', 'woocommerce' ),
220 'download-expires' => __( 'Expires', 'woocommerce' ),
221 'download-file' => __( 'Download', 'woocommerce' ),
222 'download-actions' => '&nbsp;',
223 )
224 );
225
226 if ( ! has_filter( 'woocommerce_account_download_actions' ) ) {
227 unset( $columns['download-actions'] );
228 }
229
230 return $columns;
231 }
232
233 /**
234 * Get My Account > Payment methods columns.
235 *
236 * @since 2.6.0
237 * @return array
238 */
239 function wc_get_account_payment_methods_columns() {
240 return apply_filters(
241 'woocommerce_account_payment_methods_columns',
242 array(
243 'method' => __( 'Method', 'woocommerce' ),
244 'expires' => __( 'Expires', 'woocommerce' ),
245 'actions' => '&nbsp;',
246 )
247 );
248 }
249
250 /**
251 * Get My Account > Payment methods types
252 *
253 * @since 2.6.0
254 * @return array
255 */
256 function wc_get_account_payment_methods_types() {
257 return apply_filters(
258 'woocommerce_payment_methods_types',
259 array(
260 'cc' => __( 'Credit card', 'woocommerce' ),
261 'echeck' => __( 'eCheck', 'woocommerce' ),
262 )
263 );
264 }
265
266 /**
267 * Get account orders actions.
268 *
269 * @since 3.2.0
270 * @param int|WC_Order $order Order instance or ID.
271 * @return array
272 */
273 function wc_get_account_orders_actions( $order ) {
274 if ( ! is_object( $order ) ) {
275 $order_id = absint( $order );
276 $order = wc_get_order( $order_id );
277 }
278
279 $actions = array(
280 'pay' => array(
281 'url' => $order->get_checkout_payment_url(),
282 'name' => __( 'Pay', 'woocommerce' ),
283 ),
284 'view' => array(
285 'url' => $order->get_view_order_url(),
286 'name' => __( 'View', 'woocommerce' ),
287 ),
288 'cancel' => array(
289 'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
290 'name' => __( 'Cancel', 'woocommerce' ),
291 ),
292 );
293
294 if ( ! $order->needs_payment() ) {
295 unset( $actions['pay'] );
296 }
297
298 if ( ! in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ), $order ), true ) ) {
299 unset( $actions['cancel'] );
300 }
301
302 return apply_filters( 'woocommerce_my_account_my_orders_actions', $actions, $order );
303 }
304
305 /**
306 * Get account formatted address.
307 *
308 * @since 3.2.0
309 * @param string $address_type Address type.
310 * Accepts: 'billing' or 'shipping'.
311 * Default to 'billing'.
312 * @param int $customer_id Customer ID.
313 * Default to 0.
314 * @return string
315 */
316 function wc_get_account_formatted_address( $address_type = 'billing', $customer_id = 0 ) {
317 $getter = "get_{$address_type}";
318 $address = array();
319
320 if ( 0 === $customer_id ) {
321 $customer_id = get_current_user_id();
322 }
323
324 $customer = new WC_Customer( $customer_id );
325
326 if ( is_callable( array( $customer, $getter ) ) ) {
327 $address = $customer->$getter();
328 unset( $address['email'], $address['tel'] );
329 }
330
331 return WC()->countries->get_formatted_address( apply_filters( 'woocommerce_my_account_my_address_formatted_address', $address, $customer->get_id(), $address_type ) );
332 }
333
334 /**
335 * Returns an array of a user's saved payments list for output on the account tab.
336 *
337 * @since 2.6
338 * @param array $list List of payment methods passed from wc_get_customer_saved_methods_list().
339 * @param int $customer_id The customer to fetch payment methods for.
340 * @return array Filtered list of customers payment methods.
341 */
342 function wc_get_account_saved_payment_methods_list( $list, $customer_id ) {
343 $payment_tokens = WC_Payment_Tokens::get_customer_tokens( $customer_id );
344 foreach ( $payment_tokens as $payment_token ) {
345 $delete_url = wc_get_endpoint_url( 'delete-payment-method', $payment_token->get_id() );
346 $delete_url = wp_nonce_url( $delete_url, 'delete-payment-method-' . $payment_token->get_id() );
347 $set_default_url = wc_get_endpoint_url( 'set-default-payment-method', $payment_token->get_id() );
348 $set_default_url = wp_nonce_url( $set_default_url, 'set-default-payment-method-' . $payment_token->get_id() );
349
350 $type = strtolower( $payment_token->get_type() );
351 $list[ $type ][] = array(
352 'method' => array(
353 'gateway' => $payment_token->get_gateway_id(),
354 ),
355 'expires' => esc_html__( 'N/A', 'woocommerce' ),
356 'is_default' => $payment_token->is_default(),
357 'actions' => array(
358 'delete' => array(
359 'url' => $delete_url,
360 'name' => esc_html__( 'Delete', 'woocommerce' ),
361 ),
362 ),
363 );
364 $key = key( array_slice( $list[ $type ], -1, 1, true ) );
365
366 if ( ! $payment_token->is_default() ) {
367 $list[ $type ][ $key ]['actions']['default'] = array(
368 'url' => $set_default_url,
369 'name' => esc_html__( 'Make default', 'woocommerce' ),
370 );
371 }
372
373 $list[ $type ][ $key ] = apply_filters( 'woocommerce_payment_methods_list_item', $list[ $type ][ $key ], $payment_token );
374 }
375 return $list;
376 }
377
378 add_filter( 'woocommerce_saved_payment_methods_list', 'wc_get_account_saved_payment_methods_list', 10, 2 );
379
380 /**
381 * Controls the output for credit cards on the my account page.
382 *
383 * @since 2.6
384 * @param array $item Individual list item from woocommerce_saved_payment_methods_list.
385 * @param WC_Payment_Token $payment_token The payment token associated with this method entry.
386 * @return array Filtered item.
387 */
388 function wc_get_account_saved_payment_methods_list_item_cc( $item, $payment_token ) {
389 if ( 'cc' !== strtolower( $payment_token->get_type() ) ) {
390 return $item;
391 }
392
393 $card_type = $payment_token->get_card_type();
394 $item['method']['last4'] = $payment_token->get_last4();
395 $item['method']['brand'] = ( ! empty( $card_type ) ? ucfirst( $card_type ) : esc_html__( 'Credit card', 'woocommerce' ) );
396 $item['expires'] = $payment_token->get_expiry_month() . '/' . substr( $payment_token->get_expiry_year(), -2 );
397
398 return $item;
399 }
400
401 add_filter( 'woocommerce_payment_methods_list_item', 'wc_get_account_saved_payment_methods_list_item_cc', 10, 2 );
402
403 /**
404 * Controls the output for eChecks on the my account page.
405 *
406 * @since 2.6
407 * @param array $item Individual list item from woocommerce_saved_payment_methods_list.
408 * @param WC_Payment_Token $payment_token The payment token associated with this method entry.
409 * @return array Filtered item.
410 */
411 function wc_get_account_saved_payment_methods_list_item_echeck( $item, $payment_token ) {
412 if ( 'echeck' !== strtolower( $payment_token->get_type() ) ) {
413 return $item;
414 }
415
416 $item['method']['last4'] = $payment_token->get_last4();
417 $item['method']['brand'] = esc_html__( 'eCheck', 'woocommerce' );
418
419 return $item;
420 }
421
422 add_filter( 'woocommerce_payment_methods_list_item', 'wc_get_account_saved_payment_methods_list_item_echeck', 10, 2 );
423