autoship_add_to_scheduled_order_endpoint_redirect (function)

( src/pages.php) Sets Up the autoship Add to Scheduled Orders endpoint redirect. It takes the $redirect (url) and the logged in Wordpress $user as its parameters.

Function

/**
 * Sets Up the autoship Add to Scheduled Orders endpoint redirect.
 * @param string $redirect The url redirect. Optional. Default null
 * @param WP_User $user The user who logged in.
 * @return string|NULL The redirect string or null.
 */
function autoship_add_to_scheduled_order_endpoint_redirect( $redirect = NULL, $user = NULL  ){

  global $wp_query;

  // Check for woocommerce endpoint, user logged in and addtoscheduled order var.
  if ( ! apply_filters( 'autoship_add_to_scheduled_order_endpoint_redirect_validation', isset( $wp_query->query_vars['scheduled-orders'] ) && is_account_page() && isset( $_GET['action'] ) && !empty( $_GET['action'] ) ) ){

    return $redirect;

  // If the user isn't logged in let the existing controls deal with it.
  } else if ( ! is_user_logged_in() ) {

    return $redirect;

  // Ahhh it's ours - fire away.
  } else if ( apply_filters( 'autoship_is_add_to_scheduled_order_endpoint_redirect_action', true )){

    do_action( 'autoship_pre_add_to_scheduled_order_link_handler' );

    $success = autoship_add_to_scheduled_order_endpoint_wrapper( $_GET['action'] );

    do_action( 'autoship_post_add_to_scheduled_order_link_handler', $success );

    wp_redirect( autoship_get_scheduled_orders_url() );
		exit();

  }

}