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