__( 'Abandoned Cart Webhooks for WooCommerce', 'abandoned-cart-webhooks-for-woocommerce' ), 'callback' => array( __CLASS__, 'export' ) ); return $items; } ); add_filter( 'wp_privacy_personal_data_erasers', static function ( $items ) { $items['acpw'] = array( 'eraser_friendly_name' => __( 'Abandoned Cart Webhooks for WooCommerce', 'abandoned-cart-webhooks-for-woocommerce' ), 'callback' => array( __CLASS__, 'erase' ) ); return $items; } ); } public static function policy_content() { if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) { return; } $content = '
' . esc_html__( 'Suggested text: When cart tracking is enabled, this store records cart contents, activity time, the account identifier and role labels, and contact/address fields supplied during checkout. By default, carts without a valid email address are not sent to a webhook. The store administrator can enable transmission of carts without email addresses. Eligible cart data is transmitted to the HTTPS endpoint configured by the store owner after the chosen inactivity period. The receiving application is selected and managed by the store owner; no webhook provider is built into this plugin.', 'abandoned-cart-webhooks-for-woocommerce' ) . '
'; $content .= '' . esc_html__( 'Optional saved-cart recovery is off by default. If enabled, an expiring link can restore items on another device without signing the visitor in or transferring contact details. Anyone holding the link, including a forwarded-link recipient, can use it. No email ownership verification or verification messages are provided.', 'abandoned-cart-webhooks-for-woocommerce' ) . '
'; $content .= '' . esc_html__( 'The store owner configures inactivity, recipient cooldown, history and retention settings. Cleanup depends on scheduled tasks and may retain unexpired recovery records or in-flight deliveries. Records linked to a known email can be exported or erased through the WordPress privacy tools; anonymous carts with no email cannot be located by email alone. Copies in receiving applications, order/session records and backups require separate handling. Edit this suggested text to identify your actual endpoint operator, purposes, legal basis and retention periods.', 'abandoned-cart-webhooks-for-woocommerce' ) . '
'; wp_add_privacy_policy_content( __( 'Abandoned Cart Webhooks for WooCommerce', 'abandoned-cart-webhooks-for-woocommerce' ), wp_kses_post( $content ) ); } private static function subject_pattern( $email ) { global $wpdb; // Match an exact JSON email property, including prior or nested event recipients. $property = substr( wp_json_encode( array( 'email' => $email ) ), 1, -1 ); return '%' . $wpdb->esc_like( $property ) . '%'; } public static function export( $email, $page = 1 ) { global $wpdb; if ( ! is_email( $email ) ) { return array( 'data' => array(), 'done' => true ); } $carts = ACPW_Store::carts(); $events = ACPW_Store::events(); $like = self::subject_pattern( $email ); // Paginate records rather than carts, so one cart with many events cannot create an unbounded page. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin-owned queue/privacy tables and transaction locks require current uncached database state; all values/identifiers are prepared separately. $rows = $wpdb->get_results( $wpdb->prepare( "SELECT 'cart' AS kind,c.id,c.cart_uuid,c.status,c.snapshot AS content,c.created_at FROM %i c WHERE (c.email = %s OR c.snapshot LIKE %s OR EXISTS (SELECT 1 FROM %i p WHERE p.cart_uuid = c.cart_uuid AND p.payload LIKE %s)) UNION ALL SELECT 'event' AS kind,e.id,e.cart_uuid,e.status,e.payload AS content,e.created_at FROM %i e INNER JOIN %i c ON c.cart_uuid = e.cart_uuid WHERE (c.email = %s OR c.snapshot LIKE %s OR EXISTS (SELECT 1 FROM %i p WHERE p.cart_uuid = c.cart_uuid AND p.payload LIKE %s)) ORDER BY kind,id LIMIT 50 OFFSET %d", $carts, $email, $like, $events, $like, $events, $carts, $email, $like, $events, $like, ( max( 1, (int) $page ) - 1 ) * 50 ) ); $data = array(); foreach ( $rows as $row ) { $data[] = array( 'group_id' => 'acpw', 'group_label' => __( 'Abandoned Cart Webhooks for WooCommerce', 'abandoned-cart-webhooks-for-woocommerce' ), 'item_id' => 'acpw-' . $row->kind . '-' . $row->id, 'data' => array( array( 'name' => __( 'Record type', 'abandoned-cart-webhooks-for-woocommerce' ), 'value' => $row->kind ), array( 'name' => __( 'Cart ID', 'abandoned-cart-webhooks-for-woocommerce' ), 'value' => $row->cart_uuid ), array( 'name' => __( 'Status', 'abandoned-cart-webhooks-for-woocommerce' ), 'value' => $row->status ), array( 'name' => __( 'Created (UTC)', 'abandoned-cart-webhooks-for-woocommerce' ), 'value' => gmdate( 'c', (int) $row->created_at ) ), array( 'name' => __( 'Stored cart data', 'abandoned-cart-webhooks-for-woocommerce' ), 'value' => $row->content ), ), ); } return array( 'data' => $data, 'done' => count( $rows ) < 50 ); } public static function erase( $email, $page = 1 ) { global $wpdb; if ( ! is_email( $email ) ) { return array( 'items_removed' => false, 'items_retained' => false, 'messages' => array(), 'done' => true ); } $carts = ACPW_Store::carts(); $events = ACPW_Store::events(); $like = self::subject_pattern( $email ); $removed = false; $error = false; // Always take the first remaining batch: anonymisation removes its email from the result set. // In-flight HTTP cannot be recalled; leave that cart intact and explicitly report retention. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin-owned queue/privacy tables and transaction locks require current uncached database state; all values/identifiers are prepared separately. $ids = $wpdb->get_col( $wpdb->prepare( "SELECT c.cart_uuid FROM %i c WHERE (c.email = %s OR c.snapshot LIKE %s OR EXISTS (SELECT 1 FROM %i p WHERE p.cart_uuid = c.cart_uuid AND p.payload LIKE %s)) AND NOT EXISTS (SELECT 1 FROM %i e WHERE e.cart_uuid = c.cart_uuid AND e.status IN ('sending','test_pending')) ORDER BY c.id LIMIT 25", $carts, $email, $like, $events, $like, $events ) ); foreach ( $ids as $uuid ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin-owned queue/privacy tables and transaction locks require current uncached database state; all values/identifiers are prepared separately. $wpdb->query( 'START TRANSACTION' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin-owned queue/privacy tables and transaction locks require current uncached database state; all values/identifiers are prepared separately. $cart = $wpdb->get_row( $wpdb->prepare( "SELECT c.id FROM %i c WHERE c.cart_uuid = %s AND (c.email = %s OR c.snapshot LIKE %s OR EXISTS (SELECT 1 FROM %i p WHERE p.cart_uuid = c.cart_uuid AND p.payload LIKE %s)) FOR UPDATE", $carts, $uuid, $email, $like, $events, $like ) ); if ( ! $cart ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin-owned queue/privacy tables and transaction locks require current uncached database state; all values/identifiers are prepared separately. $wpdb->query( 'ROLLBACK' ); continue; } // Lock events too, serialising against a delivery claim before removing its payload. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin-owned queue/privacy tables and transaction locks require current uncached database state; all values/identifiers are prepared separately. $states = $wpdb->get_col( $wpdb->prepare( "SELECT status FROM %i WHERE cart_uuid = %s FOR UPDATE", $events, $uuid) ); if ( array_intersect( array( 'sending', 'test_pending' ), $states ) ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin-owned queue/privacy tables and transaction locks require current uncached database state; all values/identifiers are prepared separately. $wpdb->query( 'ROLLBACK' ); continue; } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Write plugin-owned transactional state through the WordPress database API; cached state would invalidate queue/privacy guarantees. $ok = $wpdb->delete( $events, array( 'cart_uuid' => $uuid ) ); if ( false !== $ok ) { // Retain only a minimal suppression marker until normal age cleanup. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Write plugin-owned transactional state through the WordPress database API; cached state would invalidate queue/privacy guarantees. $ok = $wpdb->update( $carts, array( 'email' => '', 'user_id' => 0, 'session_hash' => '', 'snapshot' => '{}', 'content_hash' => '', 'order_id' => 0, 'status' => 'erased' ), array( 'id' => $cart->id ) ); } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin-owned queue/privacy tables and transaction locks require current uncached database state; all values/identifiers are prepared separately. ( false === $ok ? $wpdb->query( 'ROLLBACK' ) : $wpdb->query( 'COMMIT' ) ); $error = $error || false === $ok; $removed = $removed || false !== $ok; } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin-owned queue/privacy tables and transaction locks require current uncached database state; all values/identifiers are prepared separately. $retained = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM %i c WHERE (c.email = %s OR c.snapshot LIKE %s OR EXISTS (SELECT 1 FROM %i p WHERE p.cart_uuid = c.cart_uuid AND p.payload LIKE %s))", $carts, $email, $like, $events, $like ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin-owned queue/privacy tables and transaction locks require current uncached database state; all values/identifiers are prepared separately. $eligible = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM %i c WHERE (c.email = %s OR c.snapshot LIKE %s OR EXISTS (SELECT 1 FROM %i p WHERE p.cart_uuid = c.cart_uuid AND p.payload LIKE %s)) AND NOT EXISTS (SELECT 1 FROM %i e WHERE e.cart_uuid = c.cart_uuid AND e.status IN ('sending','test_pending'))", $carts, $email, $like, $events, $like, $events ) ); if ( ! $retained && ! ACPW_Store::forget( 'recipient', strtolower( $email ) ) ) { $error = true; } $messages = array(); if ( $error || ( $retained && ! $eligible ) ) { $messages[] = __( 'Some cart data was retained because delivery was in flight or storage failed. Retry erasure after deliveries finish. Data already sent to your webhook, email service, WooCommerce sessions or backups must be handled separately.', 'abandoned-cart-webhooks-for-woocommerce' ); } return array( 'items_removed' => $removed, 'items_retained' => $error || ( $retained > 0 && ! $eligible ), 'messages' => $messages, 'done' => $error || 0 === $eligible ); } }