首页 > 解决方案 > 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
        ];
}

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

标签: phpwordpresswoocommercehook-woocommerce

解决方案


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

推荐阅读