简体   繁体   中英

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');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM