从Woocommerce重定向到Php核心,并在URL中使用订单ID



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

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

这是否可能或有任何其他方法可以完成此任务?

您可以使用Wordpress 专用template_redirect钩子在购买后进行重定向,并通过 url 传递任何订单数据,如以下示例所示:

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
}
}

代码进入函数.php活动子主题(活动主题(的文件。经过测试并工作。

相关: 如何获取WooCommerce订单详细信息

最新更新