php - 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
];
}
推荐阅读
- event-handling - 如何在 webComponent 中获取 event.target 和 event.currentTarget(在影子根中)
- node.js - TypeError:无法读取未定义的属性“basename”
- sqlite - 表 2 中不存在表 1 中的行的两个表中的 sql 行数
- javascript - oidc-client 从本地主机或其他 URL 配置发现文档
- angular - Angular 8嵌套FormBuilder找不到控件
- django - Django/Apache - 从网络驱动器读取文件 (Windows)
- python-3.x - 来自 pynput 的侦听器阻塞 on_press 中的函数,直到它结束运行
- haskell - 堆栈构建失败并出现 LLD 错误
- asp.net-core - ASP NET Core Web API 返回指向图像的链接失败
- python - 过滤外键项