Changing the text on “add to cart” button inside loop

What I am gonna do at the moment is to change the infamous “Add to cart” text on the buttons inside the loop. Official Woocommerce suggests using a plugin here but if you know me you already guessed if I would follow it. Drumbeat ….. and the answer for those who don’t know me is I’m not gonna. 🙂

Apparently, I had already solved the solution. To change the text we use a woocommerce_product_add_to_cart_text filter hook.

add_filter( 'woocommerce_product_add_to_cart_text', 'mnaghdi_archive_add_to_cart_text' );
function mnaghdi_archive_add_to_cart_text($text) {
  if($text == 'Add to cart')
    return ' +';
  else 
    return $text;
}

I also bring here the filter for single product page for later reference

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

Leave a Reply

Your email address will not be published. Required fields are marked *