2017-09-05 82 views
1

通常在WooCommerce提交的訂單將重定向到/order-received/一旦付款完成。WooCommerce訂單收到重定向基於付款方式

是否有可能將客戶重定向到特定付款方式的自定義頁面?

例如:

Payment method 1 -> /order-received/ 
Payment method 2 -> /custom-page/ 
Payment method 3 -> /order-received/ 

回答

0

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

enter image description here

相關問題