【问题标题】:Woocommerce: How to redirect to a new page from 'process_payment' function?Woocommerce:如何从“process_payment”功能重定向到新页面?
【发布时间】:2021-12-13 08:38:26
【问题描述】:

我正在尝试在 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
        ];
}

如果有任何进一步的信息需要,请随时发表评论。

【问题讨论】:

  • 错误是什么?
  • @Bhautik 感谢您的评论。我什至无法重定向到我想要的页面...Failed to load resource: the server responded with a status of 500 () 我认为这是因为我没有正确设置重定向 URL。所以我正在寻找一种正确的方法来重定向到一个页面,并且我可以将数据传递到新页面。
  • 你检查错误日志了吗?

标签: php wordpress woocommerce hook-woocommerce


【解决方案1】:

更新: 以下代码是我的解决方案。 由于我只需要重定向到某个地方让客户处理付款,因此通过重定向到/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
  ];
}

【讨论】:

    猜你喜欢
    • 2018-11-21
    • 2019-07-16
    • 1970-01-01
    • 2016-11-18
    • 1970-01-01
    • 1970-01-01
    • 2021-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多