Automattic\WooCommerce\Internal\StockNotifications\Emails

EmailActionController::process_unsubscribe_action │ private │ WC 1.0

If the unsubscribe key matches, it updates the notification status to cancelled.

Метод класса: EmailActionController{}

Возвращает

void. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->process_unsubscribe_action( $notification, $action_key ): void;
$notification(Notification) (обязательный)
The Notification to process.
$action_key(строка) (обязательный)
The action key to verify.

Код EmailActionController::process_unsubscribe_action() WC 11.2.2

private function process_unsubscribe_action( Notification $notification, string $action_key ): void {
	if ( $notification->check_unsubscribe_key( $action_key ) ) {
		$notification->set_status( NotificationStatus::CANCELLED );
		$notification->set_cancellation_source( NotificationCancellationSource::USER );
		$notification->set_date_cancelled( time() );
		$notification->save();

		// We need a cookie-based session for notices to work on frontend pages.
		if ( WC()->session instanceof \WC_Session_Handler && ! WC()->session->has_session() ) {
			WC()->session->set_customer_session_cookie( true );
		}

		$product = wc_get_product( $notification->get_product_id() );

		/* translators: %2$s product name, %1$s user email */
		$notice_text = sprintf( esc_html__( 'Successfully unsubscribed %1$s. You will not receive a notification when "%2$s" becomes available.', 'woocommerce' ), $notification->get_user_email(), $product->get_name() );
		wc_add_notice( $notice_text );
		/**
		 * `woocommerce_customer_stock_notification_unsubscribe_redirect_url` filter.
		 *
		 * @since 10.2.0
		 *
		 * @param  string  $url
		 * @return string
		 */
		$url = apply_filters( 'woocommerce_customer_stock_notification_unsubscribe_redirect_url', get_permalink( wc_get_page_id( 'shop' ) ) );
		wp_safe_redirect( $url );
		exit;
	}
}