通常在 WooCommerce 中提交的订单会在/order-received/
付款完成后重定向到。
是否可以将客户重定向到特定付款方式的自定义页面?
例如:
Payment method 1 -> /order-received/
Payment method 2 -> /custom-page/
Payment method 3 -> /order-received/
通常在 WooCommerce 中提交的订单会在/order-received/
付款完成后重定向到。
是否可以将客户重定向到特定付款方式的自定义页面?
例如:
Payment method 1 -> /order-received/
Payment method 2 -> /custom-page/
Payment method 3 -> /order-received/
使用条件函数将自定义函数挂在template_redirect
操作钩子中,is_wc_endpoint_url()
并针对您想要的付款方式将客户重定向到特定页面:
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
}
}
}
代码在您的活动子主题(或主题)的 function.php 文件中或任何插件文件中。
此代码经过测试并且可以工作。
如何获取支付网关 ID(WC 设置 > 结帐选项卡):
一个小的修正。
“退出”需要在最后一个条件内
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
}
}
}