在订单接收的端点获取WooCommerce订单ID和订单键。

11 浏览
0 Comments

在订单接收的端点获取WooCommerce订单ID和订单键。

这个问题已经有答案了:

获取订单数据在成功结账钩子之后

如何获取WooCommerce订单细节

我正在尝试在重定向客户之前,在结账时获取订单编号和订单密钥(wc_order = xxx参数),但我不确定该怎么做。 我的代码如下,但它不起作用:

add_action( 'template_redirect', 'ui_redirect' );
function ui_redirect(){
    global $woocommerce;
    //if the current page is the order received and if there's an order key
    if (is_wc_endpoint_url( 'order-received' ) ) {    
        $order_key = wc_get_order_id_by_order_key( $_GET['key'] );
        $order_id = wc_get_order( $order_id );
        wp_redirect( 'redirection here with parameters');
        exit;
    }
}

admin 更改状态以发布 2023年5月21日
0
0 Comments

add_action( 'woocommerce_thankyou', 'woocommerce_thankyou_redirect', 4 );
function woocommerce_thankyou_redirect( $order_id ) {
    //$order_id. // This contains the specific ID of the order
    $order       = wc_get_order( $order_id );
    $order_key   = $order->get_order_key();
    wp_redirect( 'redirection here with parameters' );
    exit;
}

试试这段代码片段。

0