WooCommerce 即將包含的一個非常常見的功能 – 同意我的意見?同時,我們可以簡單地新增一些程式碼到我們的 functions.php 並將買方重定向到感謝頁面。可能,此感謝頁面將具有特定的加售,社交媒體分享和其他可幫助您轉換額外銷售的資訊。所以,這是我們能做的。

WooCommerce 重定向自定義謝謝頁面

我們的 WooCommerce 問題:將新訂單重定向到自定義謝謝頁面

PHP Snippet 1(更快的重定向):重定向到自定義謝謝頁面

 /**  * @snippet       WooCommerce: Redirect to Custom Thank you Page   * @sourcecode    https://businessbloomer.com/?p=490  * @author        Rodolfo Melogli  * @testedwith    WooCommerce 2.5.5  */  // Redirect custom thank you  add_action( 'woocommerce_thankyou', 'bbloomer_redirectcustom');  function bbloomer_redirectcustom( $order_id ){     $order = new WC_Order( $order_id );      $url = 'https://yoursite.com/custom-url';      if ( $order->status != 'failed' ) {         wp_redirect($url);         exit;     } }  

PHP Snippet 2(帶 JS):重定向到自定義謝謝頁面

 /**  * @snippet       WooCommerce: Redirect to Custom Thank you Page   * @sourcecode    https://businessbloomer.com/?p=490  * @author        Rodolfo Melogli  * @compatible    WooCommerce 2.4.7  */  // Redirect custom thank you  add_action( 'woocommerce_thankyou', 'bbloomer_redirectcustom');  function bbloomer_redirectcustom( $order_id ){     $order = new WC_Order( $order_id );      $url = 'https://yoursite.com/custom-url';      if ( $order->status != 'failed' ) {         echo "<script type='text/javascript'>window.location = '" . $url . "'</script>";     } } 

“重定向對我來說不行嗎?”

我最近在一個客戶的網站上工作,並使用了上面的兩個片段 – 沒有任何工作。我甚至嘗試使用重定向外掛(簡單 301 重定向),但是也沒有。

這是我發現的:在編輯 WooCommerce 端點設定時,他在 “訂單” 和 “已收到” 之間留下了一個空白(見下圖,Google 將丹麥文字翻譯成英文)。

就是這樣

破碎感謝頁面和重定向也不會工作!


可以在哪裡新增此程式碼?

您可以將 PHP 程式碼片段放置在主題或子主題的 functions.php 檔案的底部(如果是 CSS 程式碼,請新增到主題的 style.css 檔案底部),修改之前建議先備份原始檔案,若出現錯誤請先刪除此程式碼。


這段程式碼是否正常可用?

或者是您有更好的解決方案想要分享?請到薇曉朵 WooCommerce 中文論壇留言告知,我們希望可以幫到更多國內的 WooCommerce 使用者也希望您的參與。


需要關於 WooCommerce 的幫助?

請觀看我們提供的免費影片教程或到薇曉朵 WooCommerce 中文論壇提問,會有專業技術團隊提供相關幫助。