Woocommerce:如何从"process_payment"功能重定向到新页面?



我试图在Woocommerce上建立一个自定义支付网关。我试图从process_payment重定向到付款页面的新页面。

是否有任何适当的方式来重定向到一个页面,我也可以通过我需要的数据?

我的文件夹结构:

wp-content
|_ plugins
|_ my-payment
|_ redirect_page.php
wc_my_gateway.php

我目前在wc_my_gateway.php中编辑的process_payment函数:

public function process_payment($order_id)
{
global $woocommerce;
$order = new WC_Order($order_id);

// todo something ...

$redirect_url = plugin_dir_url(__FILE__) . 'redirect_page.php';
return [
'result' => 'success', // return success status
'redirect' => $redirect_url, // web page url to redirect
];
}

如需进一步资料,请随时提出意见。

更新:下面的代码是我的解决方案。由于我只需要重定向到客户端处理付款的某个地方,通过重定向到/checkout/order-pay页面,我可以尝试使用我自己的网关自定义支付过程所需的内容。

public function process_payment($order_id){
...
return [
'result' => 'success', // return success status
'redirect' => apply_filters('process_payment_redirect', $order->get_checkout_payment_url(true), $order), // web page redirect
];
}

最新更新