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