WooCommerce订单收到重定向基于付款方式
问题描述:
通常在WooCommerce提交的订单将重定向到/order-received/
一旦付款完成。WooCommerce订单收到重定向基于付款方式
是否有可能将客户重定向到特定付款方式的自定义页面?
例如:
Payment method 1 -> /order-received/
Payment method 2 -> /custom-page/
Payment method 3 -> /order-received/
答
随着使用条件函数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设置>结帐标签):