2017-07-21 55 views
2

我希望在用戶點擊添加到購物車按鈕後完全刪除任何重定向。在WooCommerce添加到購物車後停止重定向

其實我沒有使用產品頁面。
我正在使用一個簡單的按鈕,鏈接到產品,如下所示:?add-to-cart=492

我的用戶將點擊我的頁面上的幾個「添加到購物車」按鈕,因此他不能在點擊第一個按鈕後重定向到任何頁面。

在頁面末尾,他會找到一個CHECKOUT按鈕來付款,就是這樣。

任何想法如何實現這一目標?

感謝

回答

1

更新:

你簡單的HTML 「添加到購物車」 按鈕鏈接實際上是例如像(該href值)

<a href="http://my-domain.com/site2/?add-to-cart=492" target="_self" class="button white is-larger carrinho"> 
    <span>ESCOLHER PACOTE</span> 
</a> 

因此,他們每次重定向到您的家庭pag Ë


2解決方法:

1)使用WooCommerce short code [add-to-cart]這樣:**

  • 沒有價格:[add_to_cart id="492" show_price="false"]
  • 隨着價格:[add_to_cart id="492"]

2)的HTML您的網頁文本編輯器代碼 - 爲了防止重定向,href屬性應該是:

<a href="?add-to-cart=492" class="button white is-larger carrinho"> 
    <span>ESCOLHER PACOTE</span> 
</a> 

這次你的客戶不會重新定向如前 ...


Checkout按鈕

要完成,這裏是一個自定義簡碼,將輸出 「去結算」 按鈕:

if(!function_exists('proceed_to_checkout_button')) { 
    function proceed_to_checkout_button() { 

     $checkout_url = wc_get_checkout_url(); 
     $button_txt = __('Proceed to checkout', 'woocommerce'); 

     $output = '<div class="wc-proceed-to-checkout"> 
      <a href="'. $checkout_url .'" class="checkout-button button alt wc-forward"> 
       '. $button_txt .' 
      </a> 
     </div>'; 

     return $output; 
    } 
    add_shortcode('checkout_button', 'proceed_to_checkout_button'); 
} 

代碼放在功能。你的活動兒童主題(或主題)的php文件或任何插件文件。

用法:只是添加到您的網頁編輯器:[checkout_button]


原來的答覆:

首先,在WooCommerce設置您需要:

  • 啓用** Ajax的上加載到購物車按鈕(Woocommerce>設置>產品>顯示器)
  • 禁用添加到購物車按鈕重定向(Woocommerce>設置>產品>顯示器)

然後你就可以使用添加自定義「去結算」按鈕:

  • 任何經典的WordPress菜單(外觀>菜單)
  • 隨着唱的自定義代碼樂產品頁面和產品檔案:
add_action('woocommerce_after_single_product', 'custom_checkout_button', 100); 
add_action('woocommerce_after_shop_loop', 'custom_checkout_button', 100); 
function custom_checkout_button() { 

    $checkout_url = wc_get_checkout_url(); 
    $button_txt = __('Proceed to checkout', 'woocommerce'); 

    ?> 
     <div class="wc-proceed-to-checkout"> 
      <a href="<?php echo $checkout_url; ?>" class="checkout-button button alt wc-forward"> 
       <?php echo $button_txt ?> 
      </a> 
     </div> 
    <?php 
} 

代碼放在您的活動子主題(或主題)的function.php文件或也以任何插件文件。

按鈕「繼續結帳」將顯示在此頁面的底部。


如果你想跳過購物車頁面:

add_action('template_redirect', 'skip_cart_page_redirecting_to_checkout'); 
function skip_cart_page_redirecting_to_checkout() { 

    // If is cart page and cart is not empty 
    if(is_cart() && ! WC()->cart->is_empty()) 
     wp_redirect(wc_get_checkout_url()); 
} 

代碼放在您的活動子主題(或主題)的function.php文件或也以任何插件文件。

所有的代碼都經過測試和工作。

+0

謝謝,但添加到購物車按鈕後的重定向被按下直到發生。我在鏈接= http://vendamais.me/site2/?add-to-cart=492的常規頁面中使用了一個簡單的按鈕。我不知道這是否改變了解決方案的邏輯或不... – rfmarchetti

+0

完美!!!!!多謝了朋友!! – rfmarchetti

+0

點擊添加到購物車按鈕後,使用該簡碼「VIEW CART」文本鏈接替換該按鈕。有沒有辦法改變文字,甚至刪除鏈接?請參閱:http://take.ms/NzPhF 我設法設計它,但無法做更多。再次感謝 – rfmarchetti

相關問題