简体   繁体   English

如何用购物车图标和购物车图标以及自定义文本替换Woocommerce的“添加到购物车”按钮?

[英]How to replace Woocommerce “Add to Cart” Button with a Cart Icon and Cart Icon along with custom text?

Using the below code I was able to change the Text of "Add to Cart" button 使用以下代码,我可以更改“添加到购物车”按钮的文本

add_filter( 'add_to_cart_text', 'woo_custom_single_add_to_cart_text' );                // < 2.1
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_single_add_to_cart_text' );  // 2.1 +

function woo_custom_single_add_to_cart_text() {

    return __( 'My Button Text', 'woocommerce' );

}

Similarly, is it possible to replace Add to Cart Button with a Cart Icon or a Cart Icon with Custom Text? 同样,是否可以将“添加到购物车”按钮替换为购物车图标或将“自定义文本”替换为购物车图标?

不确定我的答案是否是最佳实践,但可以肯定的是,到目前为止我最容易找到它,只需转到Woocommerce文件夹并找到“ add-to-cart.php”,然后在其中; s循环只需替换esc_html( $product->add_to_cart_text() ) sprintf('<i class="fa fa-shopping-basket"></i>') esc_html( $product->add_to_cart_text() ) -如果您只想添加购物篮图标,只需将html放进去。

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

相关问题 我如何用图标替换“添加到购物车”文本(添加到购物车按钮woocommerce) - How can i replace text “Add to cart” with an icon (Add to cart button woocommerce) 将字体真棒图标添加到 Woocommerce 3 中的自定义添加到购物车按钮 - Add font awesome icon to custom add to cart button in Woocommerce 3 WooCommerce:将循环中的购物车按钮文本更改为图标 - WooCommerce: change cart button text in loop to icon 将WooCommerce上的添加到购物车按钮替换为自定义按钮 - Replace add to cart button with a custom button on WooCommerce Woocommerce 购物车图标 - Woocommerce Shopping Cart Icon 自定义添加到购物车按钮,将多个产品添加到购物车中,数量:woocommerce - Custom add to cart button to add multiple product into cart with quantity :woocommerce 替换 WooCommerce 中未登录用户的添加到购物车按钮 - Replace add to cart button for unlogged users in WooCommerce 如果在ajax上购物车不为空,则隐藏自定义按钮在Woocommerce中添加到购物车 - Hide a custom button if cart is not empty on ajax add to cart in Woocommerce 在 WooCommerce 中添加到购物车后更改自定义 Ajax 添加到购物车按钮文本 - Change custom Ajax Add to Cart button text after add to cart in WooCommerce WooCommerce 自定义 PHP 代码更改添加到购物车按钮文本 - WooCommerce custom PHP code to change Add To Cart button text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM