Automattic\WooCommerce\Internal\StockNotifications\Emails
EmailActionController::redirect_with_notice
Adds a frontend notice and redirects to the destination page of the given email action.
Method of the class: EmailActionController{}
Hooks from the method
Returns
never.
Usage
// private - for code of main (parent) class only $result = $this->redirect_with_notice( $action, $notice_text, $notice_type ): void;
- $action(string) (required)
- The email action:
'verify'or'unsubscribe'. - $notice_text(string) (required)
- The notice text to show after the redirect.
- $notice_type(string)
- The notice type:
'success','notice'or'error'.
Default:'success'
Changelog
| Since 11.3.0 | Introduced. |
EmailActionController::redirect_with_notice() EmailActionController::redirect with notice code WC 11.3.0
private function redirect_with_notice( string $action, string $notice_text, string $notice_type = 'success' ): void {
// 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 );
}
wc_add_notice( $notice_text, $notice_type );
$url = wc_get_page_permalink( 'shop' );
if ( self::ACTION_VERIFY === $action ) {
/**
* `woocommerce_customer_stock_notification_verified_redirect_url` filter.
*
* @since 10.2.0
*
* @param string $url
* @return string
*/
$url = apply_filters( 'woocommerce_customer_stock_notification_verified_redirect_url', $url );
} else {
/**
* `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', $url );
}
wp_safe_redirect( $url );
exit;
}