2015-06-23 31 views
2

現在,點擊存檔頁面上的「添加到圖表」按鈕會將產品添加到購物車,但也會將定製商重定向到某個產品的頁面,並且我試圖在點擊後禁用任何重定向「添加到購物車」按鈕。我希望定製者在點擊按鈕之前停留在他所在的同一頁面上,或者僅在添加到購物車後「刷新」頁面。禁用添加到購物車重定向

有什麼建議嗎?

/** 
* Redirect subscription add to cart to checkout page 
* 
* @param none 
*/ 
function add_to_cart_checkout_redirect() { 
     wp_safe_redirect(get_permalink(get_option(
      'woocommerce_checkout_page_id'))); 
     die(); 
    } 
add_action('woocommerce_add_to_cart', 'add_to_cart_checkout_redirect', 11 
); 
+0

你的代碼在哪裏? –

+0

@JunaidAhmed添加代碼 – Moo

+0

默認情況下,從存檔頁面添加到購物車是通過ajax完成的,不應該刷新頁面。 – helgatheviking

回答

2

這是答案。如果你想自定義重定向,有一個過濾器:

add_filter('woocommerce_add_to_cart_redirect', 'custom_redirect_function'); 
    function custom_redirect_function() { 
    return get_permalink(wc_get_page_id('shop')); 
} 
1

請下面的代碼添加到該文件的functions.php

/** 
* Set a custom add to cart URL to redirect to 
* @return string 
*/ 
function custom_add_to_cart_redirect() { 
    return 'http://www.yourdomain.com/your-page/'; 
} 
add_filter('woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect'); 

感謝

+0

謝謝。如何將「http://www.yourdomain.com/your-page/」替換爲定製者在點擊「添加到購物車」按鈕時的頁面? 謝謝 – Moo

+0

您可以添加執行添加到購物車本身的頁面。所以它會重定向到同一頁面。 –

+0

不,問題是,我需要留在相同的檔案或產品頁面,我推「添加到圖表」按鈕 – Moo

0

使用刪除動作

remove_action('woocommerce_add_to_cart', 'add_to_cart_checkout_redirect', 1); 
+0

不起作用,仍然將我重定向到某個產品的頁面 – Moo

+0

確保add_action('woocommerce_add_to_cart','add_to_cart_checkout_redirect',11 );正在導致重定向。評論它並檢查。我認爲它應該重定向到結帳頁面而不是產品頁面 – sarath

5

WooCommerce Settings

WooCommerce默認爲您提供設置。只需檢查此解決方案是否符合您的要求。

+0

非常感謝,您節省了我的時間@WisdmLabs –

相關問題