abstracts
1 year ago
admin
1 year ago
blocks
1 year ago
cli
1 year ago
customizer
2 years 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
2 years ago
libraries
3 years ago
log-handlers
2 years 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
2 years 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
2 years ago
class-wc-cart-totals.php
3 years 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
4 years ago
class-wc-countries.php
2 years 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
2 years 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
2 years ago
class-wc-embed.php
5 years 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
3 years ago
class-wc-https.php
3 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
2 years 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
2 years ago
class-wc-order-item-meta.php
4 years ago
class-wc-order-item-product.php
2 years ago
class-wc-order-item-shipping.php
2 years ago
class-wc-order-item-tax.php
4 years ago
class-wc-order-item.php
2 years ago
class-wc-order-query.php
4 years ago
class-wc-order-refund.php
2 years ago
class-wc-order.php
2 years ago
class-wc-payment-gateways.php
2 years ago
class-wc-payment-tokens.php
3 years ago
class-wc-post-data.php
1 year ago
class-wc-post-types.php
2 years ago
class-wc-privacy-background-process.php
5 years 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
5 years ago
class-wc-product-factory.php
2 years ago
class-wc-product-grouped.php
8 years ago
class-wc-product-query.php
5 years ago
class-wc-product-simple.php
1 year ago
class-wc-product-variable.php
2 years ago
class-wc-product-variation.php
1 year ago
class-wc-query.php
2 years ago
class-wc-rate-limiter.php
4 years ago
class-wc-regenerate-images-request.php
3 years ago
class-wc-regenerate-images.php
2 years ago
class-wc-register-wp-admin-settings.php
5 years ago
class-wc-rest-authentication.php
2 years ago
class-wc-rest-exception.php
5 years ago
class-wc-session-handler.php
2 years ago
class-wc-shipping-rate.php
3 years ago
class-wc-shipping-zone.php
5 years ago
class-wc-shipping-zones.php
5 years ago
class-wc-shipping.php
4 years ago
class-wc-shortcodes.php
2 years ago
class-wc-structured-data.php
1 year ago
class-wc-tax.php
3 years ago
class-wc-template-loader.php
2 years 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
2 years ago
wc-brands-functions.php
1 year ago
wc-cart-functions.php
1 year ago
wc-conditional-functions.php
2 years ago
wc-core-functions.php
1 year ago
wc-coupon-functions.php
3 years ago
wc-deprecated-functions.php
2 years ago
wc-formatting-functions.php
2 years ago
wc-notice-functions.php
2 years ago
wc-order-functions.php
1 year ago
wc-order-item-functions.php
3 years 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
3 years ago
wc-update-functions.php
1 year ago
wc-user-functions.php
1 year ago
wc-webhook-functions.php
2 years ago
wc-widget-functions.php
5 years ago
class-wc-privacy-exporters.php
445 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Personal data exporters. |
| 4 | * |
| 5 | * @since 3.4.0 |
| 6 | * @package WooCommerce\Classes |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * WC_Privacy_Exporters Class. |
| 13 | */ |
| 14 | class WC_Privacy_Exporters { |
| 15 | /** |
| 16 | * Finds and exports customer data by email address. |
| 17 | * |
| 18 | * @since 3.4.0 |
| 19 | * @param string $email_address The user email address. |
| 20 | * @return array An array of personal data in name value pairs |
| 21 | */ |
| 22 | public static function customer_data_exporter( $email_address ) { |
| 23 | $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data. |
| 24 | $data_to_export = array(); |
| 25 | |
| 26 | if ( $user instanceof WP_User ) { |
| 27 | $customer_personal_data = self::get_customer_personal_data( $user ); |
| 28 | if ( ! empty( $customer_personal_data ) ) { |
| 29 | $data_to_export[] = array( |
| 30 | 'group_id' => 'woocommerce_customer', |
| 31 | 'group_label' => __( 'Customer Data', 'woocommerce' ), |
| 32 | 'group_description' => __( 'User’s WooCommerce customer data.', 'woocommerce' ), |
| 33 | 'item_id' => 'user', |
| 34 | 'data' => $customer_personal_data, |
| 35 | ); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | return array( |
| 40 | 'data' => $data_to_export, |
| 41 | 'done' => true, |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Finds and exports data which could be used to identify a person from WooCommerce data associated with an email address. |
| 47 | * |
| 48 | * Orders are exported in blocks of 10 to avoid timeouts. |
| 49 | * |
| 50 | * @since 3.4.0 |
| 51 | * @param string $email_address The user email address. |
| 52 | * @param int $page Page. |
| 53 | * @return array An array of personal data in name value pairs |
| 54 | */ |
| 55 | public static function order_data_exporter( $email_address, $page ) { |
| 56 | $done = true; |
| 57 | $page = (int) $page; |
| 58 | $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data. |
| 59 | $data_to_export = array(); |
| 60 | $order_query = array( |
| 61 | 'limit' => 10, |
| 62 | 'page' => $page, |
| 63 | 'customer' => array( $email_address ), |
| 64 | ); |
| 65 | |
| 66 | if ( $user instanceof WP_User ) { |
| 67 | $order_query['customer'][] = (int) $user->ID; |
| 68 | } |
| 69 | |
| 70 | $orders = wc_get_orders( $order_query ); |
| 71 | |
| 72 | if ( 0 < count( $orders ) ) { |
| 73 | foreach ( $orders as $order ) { |
| 74 | $data_to_export[] = array( |
| 75 | 'group_id' => 'woocommerce_orders', |
| 76 | 'group_label' => __( 'Orders', 'woocommerce' ), |
| 77 | 'group_description' => __( 'User’s WooCommerce orders data.', 'woocommerce' ), |
| 78 | 'item_id' => 'order-' . $order->get_id(), |
| 79 | 'data' => self::get_order_personal_data( $order ), |
| 80 | ); |
| 81 | } |
| 82 | $done = 10 > count( $orders ); |
| 83 | } |
| 84 | |
| 85 | return array( |
| 86 | 'data' => $data_to_export, |
| 87 | 'done' => $done, |
| 88 | ); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Finds and exports customer download logs by email address. |
| 93 | * |
| 94 | * @since 3.4.0 |
| 95 | * @param string $email_address The user email address. |
| 96 | * @param int $page Page. |
| 97 | * @throws Exception When WC_Data_Store validation fails. |
| 98 | * @return array An array of personal data in name value pairs |
| 99 | */ |
| 100 | public static function download_data_exporter( $email_address, $page ) { |
| 101 | $done = true; |
| 102 | $page = (int) $page; |
| 103 | $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data. |
| 104 | $data_to_export = array(); |
| 105 | $downloads_query = array( |
| 106 | 'limit' => 10, |
| 107 | 'page' => $page, |
| 108 | ); |
| 109 | |
| 110 | if ( $user instanceof WP_User ) { |
| 111 | $downloads_query['user_id'] = (int) $user->ID; |
| 112 | } else { |
| 113 | $downloads_query['user_email'] = $email_address; |
| 114 | } |
| 115 | |
| 116 | $customer_download_data_store = WC_Data_Store::load( 'customer-download' ); |
| 117 | $customer_download_log_data_store = WC_Data_Store::load( 'customer-download-log' ); |
| 118 | $downloads = $customer_download_data_store->get_downloads( $downloads_query ); |
| 119 | |
| 120 | if ( 0 < count( $downloads ) ) { |
| 121 | foreach ( $downloads as $download ) { |
| 122 | $data_to_export[] = array( |
| 123 | 'group_id' => 'woocommerce_downloads', |
| 124 | /* translators: This is the headline for a list of downloads purchased from the store for a given user. */ |
| 125 | 'group_label' => __( 'Purchased Downloads', 'woocommerce' ), |
| 126 | 'group_description' => __( 'User’s WooCommerce purchased downloads data.', 'woocommerce' ), |
| 127 | 'item_id' => 'download-' . $download->get_id(), |
| 128 | 'data' => self::get_download_personal_data( $download ), |
| 129 | ); |
| 130 | |
| 131 | $download_logs = $customer_download_log_data_store->get_download_logs_for_permission( $download->get_id() ); |
| 132 | |
| 133 | foreach ( $download_logs as $download_log ) { |
| 134 | $data_to_export[] = array( |
| 135 | 'group_id' => 'woocommerce_download_logs', |
| 136 | /* translators: This is the headline for a list of access logs for downloads purchased from the store for a given user. */ |
| 137 | 'group_label' => __( 'Access to Purchased Downloads', 'woocommerce' ), |
| 138 | 'group_description' => __( 'User’s WooCommerce access to purchased downloads data.', 'woocommerce' ), |
| 139 | 'item_id' => 'download-log-' . $download_log->get_id(), |
| 140 | 'data' => array( |
| 141 | array( |
| 142 | 'name' => __( 'Download ID', 'woocommerce' ), |
| 143 | 'value' => $download_log->get_permission_id(), |
| 144 | ), |
| 145 | array( |
| 146 | 'name' => __( 'Timestamp', 'woocommerce' ), |
| 147 | 'value' => $download_log->get_timestamp(), |
| 148 | ), |
| 149 | array( |
| 150 | 'name' => __( 'IP Address', 'woocommerce' ), |
| 151 | 'value' => $download_log->get_user_ip_address(), |
| 152 | ), |
| 153 | ), |
| 154 | ); |
| 155 | } |
| 156 | } |
| 157 | $done = 10 > count( $downloads ); |
| 158 | } |
| 159 | |
| 160 | return array( |
| 161 | 'data' => $data_to_export, |
| 162 | 'done' => $done, |
| 163 | ); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Get personal data (key/value pairs) for a user object. |
| 168 | * |
| 169 | * @since 3.4.0 |
| 170 | * @param WP_User $user user object. |
| 171 | * @throws Exception If customer cannot be read/found and $data is set to WC_Customer class. |
| 172 | * @return array |
| 173 | */ |
| 174 | protected static function get_customer_personal_data( $user ) { |
| 175 | $personal_data = array(); |
| 176 | $customer = new WC_Customer( $user->ID ); |
| 177 | |
| 178 | if ( ! $customer ) { |
| 179 | return array(); |
| 180 | } |
| 181 | |
| 182 | $props_to_export = apply_filters( |
| 183 | 'woocommerce_privacy_export_customer_personal_data_props', |
| 184 | array( |
| 185 | 'billing_first_name' => __( 'Billing First Name', 'woocommerce' ), |
| 186 | 'billing_last_name' => __( 'Billing Last Name', 'woocommerce' ), |
| 187 | 'billing_company' => __( 'Billing Company', 'woocommerce' ), |
| 188 | 'billing_address_1' => __( 'Billing Address 1', 'woocommerce' ), |
| 189 | 'billing_address_2' => __( 'Billing Address 2', 'woocommerce' ), |
| 190 | 'billing_city' => __( 'Billing City', 'woocommerce' ), |
| 191 | 'billing_postcode' => __( 'Billing Postal/Zip Code', 'woocommerce' ), |
| 192 | 'billing_state' => __( 'Billing State', 'woocommerce' ), |
| 193 | 'billing_country' => __( 'Billing Country / Region', 'woocommerce' ), |
| 194 | 'billing_phone' => __( 'Billing Phone Number', 'woocommerce' ), |
| 195 | 'billing_email' => __( 'Email Address', 'woocommerce' ), |
| 196 | 'shipping_first_name' => __( 'Shipping First Name', 'woocommerce' ), |
| 197 | 'shipping_last_name' => __( 'Shipping Last Name', 'woocommerce' ), |
| 198 | 'shipping_company' => __( 'Shipping Company', 'woocommerce' ), |
| 199 | 'shipping_address_1' => __( 'Shipping Address 1', 'woocommerce' ), |
| 200 | 'shipping_address_2' => __( 'Shipping Address 2', 'woocommerce' ), |
| 201 | 'shipping_city' => __( 'Shipping City', 'woocommerce' ), |
| 202 | 'shipping_postcode' => __( 'Shipping Postal/Zip Code', 'woocommerce' ), |
| 203 | 'shipping_state' => __( 'Shipping State', 'woocommerce' ), |
| 204 | 'shipping_country' => __( 'Shipping Country / Region', 'woocommerce' ), |
| 205 | 'shipping_phone' => __( 'Shipping Phone Number', 'woocommerce' ), |
| 206 | ), |
| 207 | $customer |
| 208 | ); |
| 209 | |
| 210 | foreach ( $props_to_export as $prop => $description ) { |
| 211 | $value = ''; |
| 212 | |
| 213 | if ( is_callable( array( $customer, 'get_' . $prop ) ) ) { |
| 214 | $value = $customer->{"get_$prop"}( 'edit' ); |
| 215 | } |
| 216 | |
| 217 | $value = apply_filters( 'woocommerce_privacy_export_customer_personal_data_prop_value', $value, $prop, $customer ); |
| 218 | |
| 219 | if ( $value ) { |
| 220 | $personal_data[] = array( |
| 221 | 'name' => $description, |
| 222 | 'value' => $value, |
| 223 | ); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Allow extensions to register their own personal data for this customer for the export. |
| 229 | * |
| 230 | * @since 3.4.0 |
| 231 | * @param array $personal_data Array of name value pairs. |
| 232 | * @param WC_Order $order A customer object. |
| 233 | */ |
| 234 | $personal_data = apply_filters( 'woocommerce_privacy_export_customer_personal_data', $personal_data, $customer ); |
| 235 | |
| 236 | return $personal_data; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Get personal data (key/value pairs) for an order object. |
| 241 | * |
| 242 | * @since 3.4.0 |
| 243 | * @param WC_Order $order Order object. |
| 244 | * @return array |
| 245 | */ |
| 246 | protected static function get_order_personal_data( $order ) { |
| 247 | $personal_data = array(); |
| 248 | $props_to_export = apply_filters( |
| 249 | 'woocommerce_privacy_export_order_personal_data_props', |
| 250 | array( |
| 251 | 'order_number' => __( 'Order Number', 'woocommerce' ), |
| 252 | 'date_created' => __( 'Order Date', 'woocommerce' ), |
| 253 | 'total' => __( 'Order Total', 'woocommerce' ), |
| 254 | 'items' => __( 'Items Purchased', 'woocommerce' ), |
| 255 | 'customer_ip_address' => __( 'IP Address', 'woocommerce' ), |
| 256 | 'customer_user_agent' => __( 'Browser User Agent', 'woocommerce' ), |
| 257 | 'formatted_billing_address' => __( 'Billing Address', 'woocommerce' ), |
| 258 | 'formatted_shipping_address' => __( 'Shipping Address', 'woocommerce' ), |
| 259 | 'billing_phone' => __( 'Phone Number', 'woocommerce' ), |
| 260 | 'billing_email' => __( 'Email Address', 'woocommerce' ), |
| 261 | 'shipping_phone' => __( 'Shipping Phone Number', 'woocommerce' ), |
| 262 | ), |
| 263 | $order |
| 264 | ); |
| 265 | |
| 266 | foreach ( $props_to_export as $prop => $name ) { |
| 267 | $value = ''; |
| 268 | |
| 269 | switch ( $prop ) { |
| 270 | case 'items': |
| 271 | $item_names = array(); |
| 272 | foreach ( $order->get_items() as $item ) { |
| 273 | $item_names[] = $item->get_name() . ' x ' . $item->get_quantity(); |
| 274 | } |
| 275 | $value = implode( ', ', $item_names ); |
| 276 | break; |
| 277 | case 'date_created': |
| 278 | $value = wc_format_datetime( $order->get_date_created(), get_option( 'date_format' ) . ', ' . get_option( 'time_format' ) ); |
| 279 | break; |
| 280 | case 'formatted_billing_address': |
| 281 | case 'formatted_shipping_address': |
| 282 | $value = preg_replace( '#<br\s*/?>#i', ', ', $order->{"get_$prop"}() ); |
| 283 | break; |
| 284 | default: |
| 285 | if ( is_callable( array( $order, 'get_' . $prop ) ) ) { |
| 286 | $value = $order->{"get_$prop"}(); |
| 287 | } |
| 288 | break; |
| 289 | } |
| 290 | |
| 291 | $value = apply_filters( 'woocommerce_privacy_export_order_personal_data_prop', $value, $prop, $order ); |
| 292 | |
| 293 | if ( $value ) { |
| 294 | $personal_data[] = array( |
| 295 | 'name' => $name, |
| 296 | 'value' => $value, |
| 297 | ); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | // Export meta data. |
| 302 | $meta_to_export = apply_filters( |
| 303 | 'woocommerce_privacy_export_order_personal_data_meta', |
| 304 | array( |
| 305 | 'Payer first name' => __( 'Payer first name', 'woocommerce' ), |
| 306 | 'Payer last name' => __( 'Payer last name', 'woocommerce' ), |
| 307 | 'Payer PayPal address' => __( 'Payer PayPal address', 'woocommerce' ), |
| 308 | 'Transaction ID' => __( 'Transaction ID', 'woocommerce' ), |
| 309 | ) |
| 310 | ); |
| 311 | |
| 312 | if ( ! empty( $meta_to_export ) && is_array( $meta_to_export ) ) { |
| 313 | foreach ( $meta_to_export as $meta_key => $name ) { |
| 314 | $value = apply_filters( 'woocommerce_privacy_export_order_personal_data_meta_value', $order->get_meta( $meta_key ), $meta_key, $order ); |
| 315 | |
| 316 | if ( $value ) { |
| 317 | $personal_data[] = array( |
| 318 | 'name' => $name, |
| 319 | 'value' => $value, |
| 320 | ); |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Allow extensions to register their own personal data for this order for the export. |
| 327 | * |
| 328 | * @since 3.4.0 |
| 329 | * @param array $personal_data Array of name value pairs to expose in the export. |
| 330 | * @param WC_Order $order An order object. |
| 331 | */ |
| 332 | $personal_data = apply_filters( 'woocommerce_privacy_export_order_personal_data', $personal_data, $order ); |
| 333 | |
| 334 | return $personal_data; |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * Get personal data (key/value pairs) for a download object. |
| 339 | * |
| 340 | * @since 3.4.0 |
| 341 | * @param WC_Order $download Download object. |
| 342 | * @return array |
| 343 | */ |
| 344 | protected static function get_download_personal_data( $download ) { |
| 345 | $personal_data = array( |
| 346 | array( |
| 347 | 'name' => __( 'Download ID', 'woocommerce' ), |
| 348 | 'value' => $download->get_id(), |
| 349 | ), |
| 350 | array( |
| 351 | 'name' => __( 'Order ID', 'woocommerce' ), |
| 352 | 'value' => $download->get_order_id(), |
| 353 | ), |
| 354 | array( |
| 355 | 'name' => __( 'Product', 'woocommerce' ), |
| 356 | 'value' => get_the_title( $download->get_product_id() ), |
| 357 | ), |
| 358 | array( |
| 359 | 'name' => __( 'User email', 'woocommerce' ), |
| 360 | 'value' => $download->get_user_email(), |
| 361 | ), |
| 362 | array( |
| 363 | 'name' => __( 'Downloads remaining', 'woocommerce' ), |
| 364 | 'value' => $download->get_downloads_remaining(), |
| 365 | ), |
| 366 | array( |
| 367 | 'name' => __( 'Download count', 'woocommerce' ), |
| 368 | 'value' => $download->get_download_count(), |
| 369 | ), |
| 370 | array( |
| 371 | 'name' => __( 'Access granted', 'woocommerce' ), |
| 372 | 'value' => gmdate( 'Y-m-d', $download->get_access_granted( 'edit' )->getTimestamp() ), |
| 373 | ), |
| 374 | array( |
| 375 | 'name' => __( 'Access expires', 'woocommerce' ), |
| 376 | 'value' => ! is_null( $download->get_access_expires( 'edit' ) ) ? gmdate( 'Y-m-d', $download->get_access_expires( 'edit' )->getTimestamp() ) : null, |
| 377 | ), |
| 378 | ); |
| 379 | |
| 380 | /** |
| 381 | * Allow extensions to register their own personal data for this download for the export. |
| 382 | * |
| 383 | * @since 3.4.0 |
| 384 | * @param array $personal_data Array of name value pairs to expose in the export. |
| 385 | * @param WC_Order $order An order object. |
| 386 | */ |
| 387 | $personal_data = apply_filters( 'woocommerce_privacy_export_download_personal_data', $personal_data, $download ); |
| 388 | |
| 389 | return $personal_data; |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Finds and exports payment tokens by email address for a customer. |
| 394 | * |
| 395 | * @since 3.4.0 |
| 396 | * @param string $email_address The user email address. |
| 397 | * @param int $page Page. |
| 398 | * @return array An array of personal data in name value pairs |
| 399 | */ |
| 400 | public static function customer_tokens_exporter( $email_address, $page ) { |
| 401 | $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data. |
| 402 | $data_to_export = array(); |
| 403 | |
| 404 | if ( ! $user instanceof WP_User ) { |
| 405 | return array( |
| 406 | 'data' => $data_to_export, |
| 407 | 'done' => true, |
| 408 | ); |
| 409 | } |
| 410 | |
| 411 | $tokens = WC_Payment_Tokens::get_tokens( |
| 412 | array( |
| 413 | 'user_id' => $user->ID, |
| 414 | 'limit' => 10, |
| 415 | 'page' => $page, |
| 416 | ) |
| 417 | ); |
| 418 | |
| 419 | if ( 0 < count( $tokens ) ) { |
| 420 | foreach ( $tokens as $token ) { |
| 421 | $data_to_export[] = array( |
| 422 | 'group_id' => 'woocommerce_tokens', |
| 423 | 'group_label' => __( 'Payment Tokens', 'woocommerce' ), |
| 424 | 'group_description' => __( 'User’s WooCommerce payment tokens data.', 'woocommerce' ), |
| 425 | 'item_id' => 'token-' . $token->get_id(), |
| 426 | 'data' => array( |
| 427 | array( |
| 428 | 'name' => __( 'Token', 'woocommerce' ), |
| 429 | 'value' => $token->get_display_name(), |
| 430 | ), |
| 431 | ), |
| 432 | ); |
| 433 | } |
| 434 | $done = 10 > count( $tokens ); |
| 435 | } else { |
| 436 | $done = true; |
| 437 | } |
| 438 | |
| 439 | return array( |
| 440 | 'data' => $data_to_export, |
| 441 | 'done' => $done, |
| 442 | ); |
| 443 | } |
| 444 | } |
| 445 |