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