在订单接收的端点获取WooCommerce订单ID和订单键。
在订单接收的端点获取WooCommerce订单ID和订单键。
这个问题已经有答案了:
我正在尝试在重定向客户之前,在结账时获取订单编号和订单密钥(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日
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; }
试试这段代码片段。