2016-07-30 16 views
-3
一些自定義鏈接

我加入一個按鈕後,使用該掛鉤添加到購物車按鈕:添加一個按鈕後添加到購物車並將其重定向到WooCommerce

add_action('woocommerce_after_add_to_cart_button', array($this, 'add_button')); 

但是,當我點擊這個按鈕,它是做添加到購物車按鈕的功能。

如何自定義該按鈕鏈接(到其他頁面)

在此先感謝。

+0

什麼是回調函數'add_button'是什麼樣子?請修改您的問題以包含代碼,而不是在評論中發帖。 – helgatheviking

回答

3

您需要使用woocommerce_after_add_to_cart_button掛鉤這種方式得到你期待什麼:

add_action('woocommerce_after_add_to_cart_button', 'add_custom_button', 10, 0); 
function add_custom_button() { 
    $my_custom_link = home_url('/my_page_slug/'); 
    echo '<a class="btn-atc" href="' . esc_url($my_custom_link) .'">' . __("My text button", "my_theme_slug") . '</a>'; 
}; 

粘貼在活動兒童主題或主題的function.php文件此代碼段。

然後,你將不得不更換(代碼)正確的鏈接路徑,按鈕的名稱和主題蛞蝓爲:

  • '/my_page_slug/'
  • "My text button"
  • "my_theme_slug"

這應該工作。


這部分超出你的問題,它是關於你的造型按鈕:

你也許需要一些自定義CSS規則添加到位於你的活躍兒童主題style.css文件或主題,爲您的自定義按鈕(使用「BTN-ATC」類,而不是「BTN」)的造型外觀:

/* Based on your comment */ 

a.btn-atc { 
    background-color: #eee !important; 
    border: 2px solid #999; 
    -webkit-border-radius: 3px; 
    -moz-border-radius: 3px; 
    border-radius: 3px; 
    font-size: 20px; 
    font-weight: 500; 
    line-height: 1.7em !important; 
    margin-left: 5px; 
    margin-top: -5px; 
    position: relative; 
    padding: 0.3em 1em; 
    -webkit-transition: all 0.2s; 
    -moz-transition: all 0.2s; 
    transition: all 0.2s; 
} 
a.btn-atc:hover { 
    background-color: #666 !important; 
    color: #fff !important; 
} 
+0

嘿謝謝你的回答。我試圖改變該按鈕的css echo''; \t \t \t \t \t}; 使用class作爲btn – Ankur

+0

Css腳本 .btn {margin-left:5px; margin-top:-5px; 位置:相對; 填充:0.3em 1em; border:2px solid; -webkit-border-radius:3px; -moz-border-radius:3px; border-radius:3px; 背景:透明; font-size:20px; font-weight:500; line-height:1.7em!important; -webkit-transition:全部爲0.2s; -moz-transition:全部0。2秒; transition:全部0.2s; } – Ankur

+0

但他們的按鈕樣式沒有改變 – Ankur

相關問題