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

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

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题