0

I want to change "Add to cart" text to fontawesome icon. So i am using woocommerce filter.

add_filter( 'woocommerce_product_add_to_cart_text', 'change_text_woo' );
function change_text_woo() {
        return '<i class="fas fa-cart-plus"></i>';
}

But it shows only html code like this: enter image description here

1

Default "Add to Cart" template of WooCommerce at "templates/loop/add-to-cart.php" uses function "esc_html()" which escapes HTML blocks in return value.

The code you have added is correct. You just need to remove "esc_html()" function from "templates/loop/add-to-cart.php".

// Default Template Code
echo apply_filters( 'woocommerce_loop_add_to_cart_link',
sprintf( '<a rel="nofollow" href="%s" data-quantity="%s" data-product_id="%s" data-product_sku="%s" class="%s">%s</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr( isset( $quantity ) ? $quantity : 1 ),
esc_attr( $product->get_id() ),
esc_attr( $product->get_sku() ),
esc_attr( isset( $class ) ? $class : 'button' ),
esc_html( $product->add_to_cart_text() )
),
$product );

// Udated Template Code
echo apply_filters( 'woocommerce_loop_add_to_cart_link',
sprintf( '<a rel="nofollow" href="%s" data-quantity="%s" data-product_id="%s" data-product_sku="%s" class="%s">%s</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr( isset( $quantity ) ? $quantity : 1 ),
esc_attr( $product->get_id() ),
esc_attr( $product->get_sku() ),
esc_attr( isset( $class ) ? $class : 'button' ),
$product->add_to_cart_text()
),
$product );
  • I don't want edit here. I want to make it with woocommerce hooks. Is it possible? – bilimokur May 26 '18 at 19:20
  • 1
    WooCommerce doesn't provide any such hook. What you can do is, copy "add-to-cart.php" file from plugin templates folder and paste that in "woocommerce" folder in your active theme. Use same folder structure as you have in templates folder of WooCommerce. docs.woocommerce.com/document/template-structure – dhirenpatel22 May 27 '18 at 6:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.