douzi1991
2018-10-04 08:37
浏览 55
已采纳

使用URL中的订单ID将Woocommerce重定向到Php核心

I am working on two websites ( WordPress/Woocommerce and PHP core). I don't know what I want to do is possible or not but I need your suggestions.

I want to redirect customer after a purchase from Woocommerce to PHP core website including the Order ID in the URL.

Is this possible or there is any other way to accomplish this task?

图片转代码服务由CSDN问答提供 功能建议

我正在两个网站(WordPress / Woocommerce和PHP核心)上工作。 我不知道我想做什么是可能的,但我需要你的建议。

我想在从Woocommerce购买到PHP核心网站后重定向客户,包括订单ID URL。

这可能还是有其他方法可以完成这项任务?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dtxs9017 2018-10-04 09:57
    最佳回答

    You can use Wordpress dedicated template_redirect hook to make a redirection after a purchase and pass any order data through the url like in this example:

    add_action( 'template_redirect', 'order_received_redirection' );
    function order_received_redirection() {
        // Only on "Order received" page
        if( is_wc_endpoint_url('order-received') ) {
            global $wp;
            $order_id  = absint( $wp->query_vars['order-received'] );
            $order = wc_get_order($order_id);
            $key = isset( $_GET['key'] ) ? wc_clean( $_GET['key'] ) : $order->get_order_key();
            $total = $order->get_total();
    
            // HERE BELOW Set your redirection url
            $url_redirect = 'http://www.my-domain.com/?orderid='.$order_id . '&key=' . $key . '&total=' . $total;
    
            // Redirect 
            wp_redirect( $url_redirect );
            exit(); // Always exit
        }
    }
    

    Code goes in function.php file of your active child theme (active theme). Tested and works.

    Related: How to get WooCommerce order details

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题