doufu6423 2017-07-17 07:01
浏览 80
已采纳

购买后,WooCommerce不会重定向到内部链接

I want to redirect to custom page after purchase on woocommerce code below:

add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' );
function wc_custom_redirect_after_purchase() {
   global $wp;

   if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
        wp_redirect( get_page_by_title( About )->ID );
        exit;
    }
} 

It redirects to 'order-received' page which does not exist.

  • 写回答

1条回答 默认 最新

  • doutui7955 2017-07-17 07:36
    关注

    You have forgot th little "" around the title and you should need to use get_permalink() function too this way:

    add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' );
    function wc_custom_redirect_after_purchase() {
       global $wp;
    
       if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
            wp_redirect( get_permalink( get_page_by_title( "About" )->ID ) );
            exit;
        }
    } 
    

    Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    I have tested it and this should work now

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?