2017-03-02 33 views
2

使用Wordpress和WooCommerce,我試圖在購物車的「x」下添加一個自定義文本「刪除商品」,以從購物車中刪除商品。在X按鈕下添加一個從購物車中刪除商品的自定義文本

我試圖「檢查元素」來找到這個「x」文本圖標的位置,但我正在打磚牆。

有關我如何找到它的任何建議,並修改「x」按鈕以在下面包含文本?

謝謝。

+0

你試過了什麼? –

回答

1
add_filter('woocommerce_cart_item_remove_link', 'remove_icon_and_add_text', 10, 2); 

function remove_icon_and_add_text($string, $cart_item_key) { 
    $string = str_replace('class="remove"', '', $string); 
    return str_replace('×', 'Delete Item', $string); 
} 

請嘗試以下代碼片斷在您的活動主題的functions.php的

+0

謝謝!有效! –

1

這個小跨文本圖標位於WooCommerce templatescart/cart.phpcart/mini-cart.php。但改爲覆蓋此模板,您可以使用專用的篩選器鉤子來實現您想要執行的操作。

這裏是一個工作測試代碼,將紅十字會購物車圖標的下方添加「刪除項目」

add_filter('woocommerce_cart_item_remove_link', 'custom_filter_wc_cart_item_remove_link', 10, 2); 
function custom_filter_wc_cart_item_remove_link($sprintf, $cart_item_key) { 

    if (is_admin() && ! defined('DOING_AJAX')) 
     return $sprintf; 

    // HERE Define your additional text 
    $add_text = __('Delete item', 'woocommerce'); 

    // HERE Define the style of the text 
    $styles = 'font-size:0.8em; display:block;'; 

    $sprintf = str_replace('</a>', '</a><span class="remove-text" style="'.$styles.'">'.$add_text.'</span>', $sprintf); 

    return $sprintf; 
}; 

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

你可需要添加一些CSS樣式爲您的活動主題slyle.css文件中使用
.woocommerce a.remove CSS選擇器的紅色十字圖標。

相關問題