Right now when a product is successfully added through a form it just stays on the same page and it shows up a notice "Product Added" - but I would like to redirect to another page like example.com/user
after product is successfully added. I'm not sure how can I achieve this?
Product form controller:
public function process_submit() {
if ( ! isset( $_POST[ '_wcv-save_product' ] ) || !wp_verify_nonce( $_POST[ '_wcv-save_product' ], 'wcv-save_product' ) || !is_user_logged_in() ) {
return;
}
$can_submit_live = WC_Vendors::$pv_options->get_option( 'can_submit_live_products' );
$current_post_status = isset( $_POST[ 'post_status' ] ) ? $_POST[ 'post_status' ] : '';
$can_edit_approved = WC_Vendors::$pv_options->get_option( 'can_edit_approved_products' );
$trusted_vendor = ( get_user_meta( get_current_user_id(), '_wcv_trusted_vendor', true ) == 'yes' ) ? true: false;
$untrusted_vendor = ( get_user_meta( get_current_user_id(), '_wcv_untrusted_vendor', true ) == 'yes' ) ? true: false;
if ( $trusted_vendor ) $can_submit_live = true;
if ( $untrusted_vendor ) $can_submit_live = false;
$text = array( 'notice' => '', 'type' => 'success' );
if ( isset( $_POST[ 'post_id' ] ) && is_numeric( $_POST[ 'post_id' ] ) ) {
$post_id = $this->save_product( (int) ( $_POST[ 'post_id' ] ) );
if ( $post_id ) {
$view = get_permalink( $post_id );
if ( isset( $_POST[ 'draft_button' ] ) ) {
if ( $can_submit_live ) {
$text[ 'notice' ] = sprintf( apply_filters( 'wcv_product_draft_msg', __( 'Product draft saved.', 'wcvendors-pro' ) ), $view );
} else {
$text[ 'notice' ] = sprintf( apply_filters( 'wcv_product_draft_saved_msg', __( 'Product draft saved, pending review.', 'wcvendors-pro' ) ), $view );
}
} else {
if ( $can_submit_live ) {
$text[ 'notice' ] = sprintf( apply_filters( 'wcv_product_updated_msg', __( 'Product Updated. <a href="%s">View product.</a>', 'wcvendors-pro' ) ), $view );
} elseif( $can_edit_approved && 'pending' !== $current_post_status && 'draft' !== $current_post_status ) {
$text[ 'notice' ] = sprintf( apply_filters( 'wcv_product_updated_msg', __( 'Product Updated. <a href="%s">View product.</a>', 'wcvendors-pro' ) ), $view );
} else {
$text[ 'notice' ] = sprintf( apply_filters( 'wcv_product_review_msg', __( 'Product submitted for review. <a href="%s">Preview product.</a>', 'wcvendors-pro' ) ), $view );
}
}
} else {
$text[ 'notice' ] = apply_filters( 'wcv_product_edit_problem_msg', __( 'There was a problem editing the product.', 'wcvendors-pro' ) );
$text[ 'type' ] = 'error';
}
} else {
$post_id = $this->save_product();
$view = get_permalink( $post_id );
if ( $post_id ) {
if ( isset( $_POST[ 'draft_button' ] ) ) {
if ( $can_submit_live ) {
$text[ 'notice' ] = sprintf( apply_filters( 'wcv_product_draft_msg', __( 'Product draft saved.', 'wcvendors-pro' ) ), $view );
} else {
$text[ 'notice' ] = sprintf( apply_filters( 'wcv_product_draft_saved_msg', __( 'Product draft saved, pending review.', 'wcvendors-pro' ) ), $view );
}
} else {
if ( $can_submit_live ) {
$text[ 'notice' ] = sprintf( apply_filters( 'wcv_product_added_msg', __( 'Product Added. <a href="%s">View product.</a>', 'wcvendors-pro' ) ), $view );
} else {
$text[ 'notice' ] = sprintf( apply_filters( 'wcv_product_review_msg', __( 'Product submitted for review. <a href="%s">Preview product.</a>', 'wcvendors-pro' ) ), $view );
}
}
} else {
$text[ 'notice' ] = apply_filters( 'wcv_product_add_problem_msg', __( 'There was a problem adding the product.', 'wcvendors-pro' ) );
$text[ 'type' ] = 'error';
}
}
wc_add_notice( $text[ 'notice' ], $text[ 'type' ] );