Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 重定向到另一页,而不是显示通知_Javascript_Php_Wordpress_Forms - Fatal编程技术网

Javascript 重定向到另一页,而不是显示通知

Javascript 重定向到另一页,而不是显示通知,javascript,php,wordpress,forms,Javascript,Php,Wordpress,Forms,现在,当一个产品通过表单成功添加时,它只是停留在同一页面上,并显示一个通知“产品已添加”-但我想在成功添加产品后重定向到另一个页面,如example.com/user。我不知道如何才能做到这一点 产品表单控制器: public function process_submit() { if ( ! isset( $_POST[ '_wcv-save_product' ] ) || !wp_verify_nonce( $_POST[ '_wcv-save_product' ],

现在,当一个产品通过表单成功添加时,它只是停留在同一页面上,并显示一个通知“产品已添加”-但我想在成功添加产品后重定向到另一个页面,如
example.com/user
。我不知道如何才能做到这一点

产品表单控制器:

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' ] ); 
公共函数进程_submit(){
如果(!isset($_POST['.\u wcv-save_product'])| |!wp_verify_nonce($_POST['.\u wcv-save_product'],'wcv-save_product')| |!用户是否已登录(){
返回;
}
$can_submit_live=WC_供应商::$pv_options->get_option('can_submit_live_products');
$current_post_status=isset($_post['post_status'])?$_post['post_status']:'';
$can_edit_approved=WC_供应商::$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;
如果($trusted\u vendor)$can\u submit\u live=true;
如果($untrusted_vendor)$can_submit_live=false;
$text=array('notice'=>'',type'=>'success');
如果(isset($_POST['POST_id'])和&is_numeric($_POST['POST_id']){
$post_id=$this->save_product((int)($_post['post_id']);
如果($post_id){
$view=get\u permalink($post\u id);
如果(isset($_POST['草稿按钮])){
如果($can_submit_live){
$text['notice']=sprintf(应用过滤器('wcv\u product\u draft\u msg','wcv\u('product draft saved','wcvendors pro'),$view);
}否则{
$text['notice']=sprintf(应用过滤器('wcv\u product\u draft\u saved\u msg','wcv\u('product draft saved,pending review','wcvendors pro'),$view);
}
}否则{
如果($can_submit_live){
$text['notice']=sprintf(应用过滤器('wcv\u product\u updated\u msg','wcv\u('product updated','wcvendors pro'),$view);
}elseif($can_edit_approved和'pending'!=$current_post_status和'draft'!=$current_post_status){
$text['notice']=sprintf(应用过滤器('wcv\u product\u updated\u msg','wcv\u('product updated','wcvendors pro'),$view);
}否则{
$text['notice']=sprintf(应用过滤器('wcv\u product\u review\u msg','wcv\u产品提交审查','wcvendors pro'),$view);
}
}
}否则{
$text['notice']=apply_filters('wcv_product_edit_problem_msg',uuuu('编辑产品时出现问题','wcvendors pro');
$text['type']='error';
}
}否则{
$post_id=$this->save_product();
$view=get\u permalink($post\u id);
如果($post_id){
如果(设置($_POST['草稿按钮]){
如果($can_submit_live){
$text['notice']=sprintf(应用过滤器('wcv\u product\u draft\u msg','wcv\u('product draft saved','wcvendors pro'),$view);
}否则{
$text['notice']=sprintf(应用过滤器('wcv\u product\u draft\u saved\u msg','wcv\u('product draft saved,pending review','wcvendors pro'),$view);
}
}否则{
如果($can_submit_live){
$text['notice']=sprintf(应用过滤器('wcv\u product\u added\u msg','wcv\u('product added','wcvendors pro'),$view);
}否则{
$text['notice']=sprintf(应用过滤器('wcv\u product\u review\u msg','wcv\u产品提交审查','wcvendors pro'),$view);
}
}
}否则{
$text['notice']=apply_filters('wcv_product_add_problem_msg',uuuu('添加产品时出现问题','wcvendors pro');
$text['type']='error';
}               
}
wc_添加_通知($text['notice'],$text['type']);

functions.php
文件中添加此代码块

/**
 * Redirect users after add to cart.
 */
function my_custom_add_to_cart_redirect( $url ) {
    $url = get_permalink('/page'); // URL to redirect 
    return $url;
}
add_filter( 'woocommerce_add_to_cart_redirect', 'my_custom_add_to_cart_redirect' );
希望这对你有帮助