gpt4 book ai didi

javascript - 重定向到另一个页面而不是显示通知

转载 作者:行者123 更新时间:2023-11-29 23:50:24 26 4
gpt4 key购买 nike

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

产品表单 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' ] );

最佳答案

将此代码块添加到您的 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' );

希望对您有所帮助!!

关于javascript - 重定向到另一个页面而不是显示通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42886287/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com