WooCommerce在收到订单的端点[重复]上获得订单ID和订单密钥

问题描述 投票:1回答:1

我正在尝试在重定向客户之前在结帐时获取订单号和订单密钥(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;
    }
}

php wordpress woocommerce hook-woocommerce orders
1个回答
1
投票
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;
}

尝试此代码段。

© www.soinside.com 2019 - 2024. All rights reserved.