Automattic\WooCommerce\Internal\StockNotifications\Privacy
PrivacyEraser::erase_notification_data
Erase customer stock notification data for a given email address.
This method anonymizes the user email and sets the status of the notifications to 'cancelled'.
Method of the class: PrivacyEraser{}
No Hooks.
Returns
Array. Response containing the status of the operation and messages.
Usage
$result = PrivacyEraser::erase_notification_data( $email_address ): array;
- $email_address(string) (required)
- The email address to erase data for.
PrivacyEraser::erase_notification_data() PrivacyEraser::erase notification data code WC 10.3.6
public static function erase_notification_data( string $email_address ): array {
$response = array(
'items_removed' => false,
'items_retained' => false,
'messages' => array(),
'done' => true,
);
$notifications = NotificationQuery::get_notifications(
array(
'user_email' => $email_address,
)
);
foreach ( $notifications as $notification_id ) {
$notification = Factory::get_notification( $notification_id );
$anonymous_email = wp_privacy_anonymize_data( 'email', $email_address );
$notification->set_user_email( $anonymous_email );
$notification->set_user_id( 0 );
$notification->set_status( NotificationStatus::CANCELLED );
$notification->set_cancellation_source( NotificationCancellationSource::USER );
$notification->set_date_cancelled( current_time( 'mysql' ) );
$notification->update_meta_data( '_anonymized', 'yes' );
$notification->update_meta_data( 'email_link_action_key', '' );
$notification->save();
$response['messages'][] = sprintf(
/* translators: %d the numeric product ID */
__( 'Removed back-in-stock notification for product id: %d', 'woocommerce' ),
$notification->get_product_id()
);
$response['items_removed'] = true;
}
return $response;
}