简体   繁体   English

我如何用图标替换“添加到购物车”文本(添加到购物车按钮woocommerce)

[英]How can i replace text “Add to cart” with an icon (Add to cart button woocommerce)

I've tried to replace button text with an icon, but following code return the text not the icon. 我试图用图标替换按钮文本,但是下面的代码返回文本而不是图标。

add_filter( 'woocommerce_product_add_to_cart_text', 'woo_custom_product_add_to_cart_text' );  // 2.1 +

function woo_custom_product_add_to_cart_text() {  
    return __( '<i class="fa fa-cart-plus" aria-hidden="true"></i>', 'woocommerce' );

}

try this >> 试试这个>>

function remove_button_loop(){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}
add_action('init','remove_button_loop');
function add_to_cart_replace() {
    global $product;
    $link = $product->get_permalink();
    echo do_shortcode('<a href="'.$link.'" class="button addtocartbutton"><i class="fa fa-shopping-bag"></i></a>');
}
add_action('woocommerce_after_shop_loop_item','add_to_cart_replace');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何用购物车图标和购物车图标以及自定义文本替换Woocommerce的“添加到购物车”按钮? - How to replace Woocommerce “Add to Cart” Button with a Cart Icon and Cart Icon along with custom text? WooCommerce-如何使用具有相同购物车按钮的Ajax将多种不同的产品添加到购物车? - WooCommerce - How can I add multiple, different products to cart using ajax with same add-to-cart-Button? 将WooCommerce上的添加到购物车按钮替换为自定义按钮 - Replace add to cart button with a custom button on WooCommerce 替换 WooCommerce 中未登录用户的添加到购物车按钮 - Replace add to cart button for unlogged users in WooCommerce 如何在 WooCommerce 添加到购物车按钮下方添加文本 - How to add text underneath WooCommerce Add To Cart Button 将字体真棒图标添加到 Woocommerce 3 中的自定义添加到购物车按钮 - Add font awesome icon to custom add to cart button in Woocommerce 3 Woocommerce 添加到购物车按钮和购物车小部件 - Translate Woocommerce Add to cart button & Cart widget 如何在 Woocommerce 中的 wc_add_to_cart_message 中添加一个额外的按钮? - How can I add an extra button the the wc_add_to_cart_message in Woocommerce? 如何在Woocommerce页面顶部添加购物车按钮? - How to add the Cart button on top of the page in Woocommerce? Woocommerce - 如何将数量传递到“添加到购物车”按钮 - Woocommerce - How to pass quantity into Add to cart button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM