Automattic\WooCommerce\Internal\StockNotifications\Admin
NotificationEditPage::process_edit_form
Update notification.
Method of the class: NotificationEditPage{}
No Hooks.
Returns
null. Nothing (null).
Usage
$NotificationEditPage = new NotificationEditPage(); $NotificationEditPage->process_edit_form( $notification );
- $notification(Notification) (required)
- The notification object.
NotificationEditPage::process_edit_form() NotificationEditPage::process edit form code WC 10.3.6
public function process_edit_form( Notification $notification ) {
if ( empty( $_POST ) || empty( $_POST['wc_customer_stock_notification_action'] ) ) {
return;
}
check_admin_referer( 'woocommerce-customer-stock-notification-edit', 'customer_stock_notification_edit_security' );
$action = wc_clean( wp_unslash( $_POST['wc_customer_stock_notification_action'] ) );
switch ( $action ) {
case 'activate_notification':
$notification->set_status( NotificationStatus::ACTIVE );
$result = $notification->save();
if ( is_wp_error( $result ) ) {
$notice_message = $result->get_error_message();
NotificationsPage::add_notice( $notice_message, 'error' );
} else {
$notice_message = __( 'Notification updated.', 'woocommerce' );
NotificationsPage::add_notice( $notice_message, 'success' );
}
break;
case 'cancel_notification':
$notification->set_status( NotificationStatus::CANCELLED );
$notification->set_date_cancelled( time() );
$notification->set_date_notified( NotificationCancellationSource::ADMIN );
$result = $notification->save();
if ( is_wp_error( $result ) ) {
$notice_message = $result->get_error_message();
NotificationsPage::add_notice( $notice_message, 'error' );
} else {
$notice_message = __( 'Notification updated.', 'woocommerce' );
NotificationsPage::add_notice( $notice_message, 'success' );
}
break;
case 'send_notification':
$product = $notification->get_product();
if ( ! $product || ! $product->is_in_stock() ) {
$notice_message = __( 'Failed to send notification. Please make sure that the listed product is available.', 'woocommerce' );
NotificationsPage::add_notice( $notice_message, 'error' );
} else {
$email_manager = new EmailManager();
$email_manager->send_stock_notification_email( $notification );
$notification->set_status( NotificationStatus::SENT );
$notification->set_date_notified( time() );
$notification->save();
// translators: %s user email.
$notice_message = sprintf( __( 'Notification sent to "%s".', 'woocommerce' ), $notification->get_user_email() );
NotificationsPage::add_notice( $notice_message, 'success' );
}
break;
case 'send_verification_email':
// translators: %s user email.
$notice_message = sprintf( __( 'Verification email sent to "%s".', 'woocommerce' ), $notification->get_user_email() );
NotificationsPage::add_notice( $notice_message, 'success' );
break;
}
// Construct edit url.
$edit_url = add_query_arg(
array(
'notification_action' => 'edit',
'notification_id' => $notification->get_id(),
),
NotificationsPage::PAGE_URL
);
wp_safe_redirect( $edit_url );
exit;
}