Automattic\WooCommerce\Internal\StockNotifications\Emails
EmailActionController::process_unsubscribe_action
If the unsubscribe key matches, it updates the notification status to cancelled.
Method of the class: EmailActionController{}
Hooks from the method
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->process_unsubscribe_action( $notification, $action_key ): void;
- $notification(Notification) (required)
- The Notification to process.
- $action_key(string) (required)
- The action key to verify.
EmailActionController::process_unsubscribe_action() EmailActionController::process unsubscribe action code WC 10.3.6
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 session for notices to work.
if ( ! WC()->session->has_session() ) {
// Generate a random customer ID.
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 );
}
}