隨着使用條件函數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設置>結帳標籤):