[英]How to add FontAwesome icon instead on text in php?
我正在尝试用购物车的图标替换字符串“添加到购物车”。 问题是如何在此php代码内插入字体超赞图标<i class="fa fa-shopping-cart" aria-hidden="true"></i>
:
$text = $this->is_purchasable() && $this->is_in_stock() ? __( 'Add to cart', 'woocommerce' ) : __( 'Read more', 'woocommerce' );
return apply_filters( 'woocommerce_product_add_to_cart_text', $text, $this );
提前致谢
圣帕维尔
不熟悉woocommerce但...
你试过了吗:
$text = $this->is_purchasable() && $this->is_in_stock() ? __( '<i class="fa fa-shopping-cart" aria-hidden="true"></i>', 'woocommerce' ) : __( 'Read more', 'woocommerce' );
编辑:
根据您的评论,apply_filters函数似乎不接受HTML值作为arg,因为它是第二个参数。 因此,这是我的建议:
最简单的方法是使用jQuery:
我在此处查看了该演示: https : //demo.woothemes.com/storefront/shop/检查了“添加到购物车”按钮...就<a>
标签的类而言,其值为: class="button product_type_simple add_to_cart_button ajax_add_to_cart fa fa-cart-plus"
因此,您可以执行以下任一操作:
jQuery('a.ajax_add_to_cart').addClass('fa fa-cart-plus');
要么
jQuery('a.add_to_cart_button').addClass('fa fa-cart-plus');
编辑#2:
并且由于您尝试用图标替换文本(并且没有图标AND文本),因此请执行以下操作:
jQuery('a.ajax_add_to_cart').text('');
要么
jQuery('a.add_to_cart_button').text('');
希望这可以帮助!
-拉什
woocommerce / loop / add-to-cart.php
取代这个
sprintf( '<a rel="nofollow" href="%s" data-quantity="%s" data-product_id="%s" data-product_sku="%s" class="%s">
<i class="fa fa-shopping-cart"></i> %s</a>',
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.