Woocommerce:支付网关自定义感谢页面 [英] Woocommerce: Payment gateway custom thank you page

查看:35
本文介绍了Woocommerce:支付网关自定义感谢页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 Woocommerce 自定义支付网关插件(它基本上将用户重定向到支付服务页面,然后支付服务页面将用户重定向回指定的 URL),一切都按预期工作,但我不能似乎创建了一个自定义的感谢页面来自插件.

I'm creating a Woocommerce custom Payment Gateway plugin (it basically redirects the user to the payment service page and then the payment service page redirects the user back to an especified URL), everything is working as expected but I can't seem to create a custom thank-you page FROM THE PLUGIN.

我所说的来自插件"的意思是,如果有人安装了我的支付网关插件,他们应该能够看到自定义的感谢页面,而无需任何额外的操作,例如在 WP 中添加 Woocommerce 主题或页面.

What I mean with "from the plugin" is that if someone installs my Payment Gateway plugin they should be able to see the custom thank-you page without any aditional operation like adding a Woocommerce theme or page in WP.

这是我目前用于处理默认感谢页面的内容:

Here is what I'm currently using to handle the default thank-you page:

重定向 URL 为:$this->get_return_url($order))

感谢页面与:

add_action('woocommerce_thankyou_'.$this->id, array( $this, 'return_handler' ) );

这是我应该处理感谢页面消息的函数:

And here is my function that should handle the thankyou page messages:

public function return_handler() {
  $order_id = get_query_var('order-received');
  global $woocommerce;
  $order = new WC_Order( $order_id );
  //NEXT I JUST CHECK THE ORDER AND SHOW MESSAGES DEPENDING ON THE RESULT
}

如果有另一种方式将用户返回到将触发我的插件功能之一的 URL,这可能是一个有效的选项.

also if there is another way of returning the user to an URL that will trigger one of my plugins function, that could be a valid option.

推荐答案

认为您需要定位的过滤器是woocommerce_payment_successful_result,它位于WC_Checkout 类.

I think the filter you need to target is woocommerce_payment_successful_result which is in the WC_Checkout class.

function so_27024470_paypal_redirect( $return, $order_id ){
    $order = new WC_Order( $order_id );
    if( $order->payment_method == 'your-gateway-id' ){
        $return['redirect'] = 'http://your-redirect.com';
    }
    return $return;
}
add_action( 'woocommerce_payment_successful_result, 'so_27024470_paypal_redirect', 10, 2 );

我没有测试过这个,所以使用风险自负.

I haven't tested this, so use at your own risk.

这篇关于Woocommerce:支付网关自定义感谢页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆