get_row( $wpdb->prepare( "SELECT * FROM %i WHERE token_hash = %s AND expires_at > %d", ACPW_Store::events(), hash( 'sha256', $token ), time()) ); if ( ! $event ) { return false; } $cart = ACPW_Store::cart( $event->cart_uuid ); if ( ! $cart || in_array( $cart->status, array( 'ordered', 'empty', 'superseded', 'erased' ), true ) ) { return false; } $entry = json_decode( $event->payload, true ); return is_array( $entry ) && ( ! array_key_exists( 'recovery_enabled', $entry ) || ! empty( $entry['recovery_enabled'] ) ) ? array( 'entry' => $entry, 'cart_uuid' => $event->cart_uuid, 'event_uuid' => $event->event_uuid ) : false; } public static function handle() { $param = isset( $_GET['acpw_restore'] ) ? 'acpw_restore' : 'oacw_restore'; if ( ! isset( $_GET[ $param ] ) ) { return; } if ( ! defined( 'DONOTCACHEPAGE' ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- This is the established cache-plugin interoperability constant. define( 'DONOTCACHEPAGE', true ); } nocache_headers(); header( 'Referrer-Policy: no-referrer' ); header( 'X-Robots-Tag: noindex, nofollow' ); header( "Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'" ); if ( ! is_string( $_GET[ $param ] ) ) { self::page( __( 'Recovery link unavailable', 'abandoned-cart-webhooks-for-woocommerce' ), '
' . esc_html__( 'This recovery link is invalid.', 'abandoned-cart-webhooks-for-woocommerce' ) . '
', 400 ); } if ( ! WC()->cart || ! WC()->session ) { self::page( __( 'Recovery unavailable', 'abandoned-cart-webhooks-for-woocommerce' ), '' . esc_html__( 'The shopping cart is temporarily unavailable. Please try again.', 'abandoned-cart-webhooks-for-woocommerce' ) . '
', 503 ); } $token = sanitize_text_field( wp_unslash( $_GET[ $param ] ) ); $found = self::lookup( $token ); if ( ! $found ) { self::page( __( 'Recovery link unavailable', 'abandoned-cart-webhooks-for-woocommerce' ), '' . esc_html__( 'This link has expired, is invalid, or the cart has already been checked out.', 'abandoned-cart-webhooks-for-woocommerce' ) . '
' . esc_html__( 'Visit your cart', 'abandoned-cart-webhooks-for-woocommerce' ) . '
', 410 ); } if ( 'POST' === ( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ?? '' ) ) ) ) { $nonce = isset( $_POST['_wpnonce'] ) && is_string( $_POST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ) : ''; if ( ! wp_verify_nonce( $nonce, 'acpw_restore_' . hash( 'sha256', $token ) ) ) { self::page( __( 'Please reopen your recovery link', 'abandoned-cart-webhooks-for-woocommerce' ), '' . esc_html__( 'The confirmation expired. Open the link again and retry.', 'abandoned-cart-webhooks-for-woocommerce' ) . '
', 403 ); } $mode = isset( $_POST['mode'] ) && 'replace' === $_POST['mode'] ? 'replace' : 'merge'; $result = self::restore( $found['entry'], $mode ); if ( is_wp_error( $result ) ) { self::page( __( 'Cart could not be restored', 'abandoned-cart-webhooks-for-woocommerce' ), '' . esc_html( $result->get_error_message() ) . '
' . esc_html__( 'Visit your cart', 'abandoned-cart-webhooks-for-woocommerce' ) . '
', 409 ); } WC()->session->set_customer_session_cookie( true ); WC()->session->set( 'acpw_recovery_event', $found['event_uuid'] ); // A recovery token authorises items, never ownership of the sender's tracking identity. // Keep this browser's own identity, or generate a fresh one. Do not copy source contact data. ACPW_Capture::queue(); ACPW_Capture::flush(); WC()->cart->set_session(); WC()->session->save_data(); wp_safe_redirect( wc_get_checkout_url(), 303 ); exit; } $body = '' . esc_html__( 'This link restores saved items. It does not sign you in or copy contact details. Anyone holding this link can use it.', 'abandoned-cart-webhooks-for-woocommerce' ) . '
' . esc_html__( 'Restore the available items below using today\'s prices and stock availability. Your account and saved addresses will not be changed.', 'abandoned-cart-webhooks-for-woocommerce' ) . '