随着使用条件函数is_wc_endpoint_url()
和定位想要的付款方式为客户重定向到一个特定的页面在template_redirect
行动钩勾住了自定义函数:
add_action('template_redirect', 'thankyou_custom_payment_redirect');
function thankyou_custom_payment_redirect(){
if (is_wc_endpoint_url('order-received')) {
global $wp;
// Get the order ID
$order_id = intval(str_replace('checkout/order-received/', '', $wp->request));
// Get an instance of the WC_Order object
$order = wc_get_order($order_id);
// Set HERE your Payment Gateway ID
if($order->get_payment_method() == 'cheque'){
// Set HERE your custom URL path
wp_redirect(home_url('/custom-page/'));
}
}
exit(); // always exit
}
代码出现在您的活动子主题(或我)还是在任何插件文件中。
此代码已经过测试并可正常工作。
如何获得支付网关ID(WC设置>结帐标签):