X

Cómo cambiar el texto predeterminado del botón “Añadir al carrito” en WooCommerce

Snippets by IsItWP

¿Estás buscando una forma de cambiar el texto del botón “Añadir al carrito” por defecto en WooCommerce? Este snippet te permitirá cambiar el texto a “Donar ahora”, “Añadir producto”, “Comprar”, o lo que quieras.

Instrucciones:

  1. Añade este código al archivo functions.php de tu tema o en un plugin específico del sitio.
  2. A continuación, solo tienes que cambiar el texto “Añadir elemento” de la línea 4 por el que desees.
add_filter('woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text');

function woo_custom_cart_button_text() {
return __('Book Now', 'woocommerce');
}

Nota: Si es la primera vez que añade fragmentos de código en WordPress, consulte nuestra guía sobre cómo copiar / pegar correctamente fragmentos de código en WordPress, para no romper accidentalmente su sitio.

Si te ha gustado este fragmento de código, por favor considere revisar nuestros otros artículos en el sitio como: 30 maneras de hacer dinero en línea Blogging (en el lado).

Comentarios   Deja una respuesta

  1. Thanks alot! It solved my problem.

  2. I’m having issues with the WooCommerce Subscription “Add to cart” button. It is showing “Add to cart Sign up Now” rather than just “Sign up Now”. Any suggestions of how to fix this?

  3. I would like to replace the black box button with a shopping cart icon. Please advise how to do this.

  4. Any solution in a language that is not english, it looks that the code is working but only for enlish. if i use lets say Greek it will display an empty add to cart butoon.

  5. Hi!

    how can I make the term inside the function ready to be translated?
    I made this attempt but it returns a critical error

    I tried to make this change:

    // change text button add to cartList
    add_filter( ‘woocommerce_product_add_to_cart_text’, ‘nlwc_custom_button_text’ );

    function nlwc_custom_button_text() {
    return __(”);
    }

  6. Hi, works ok for me in all products of the shop, but is it possible to apply to a concrete product? only for ‘product_id=1299’ ?? works?

  7. Worked for me. Thank you

  8. Hi, the button completely disappeared for me after i added the code in functions.php

    I restored my functions.php to its original state, but the button is not showing anymore on the frontend.

    1. You may want to check that no CSS is hiding the button.

  9. Is it possible to replace the text with a Font Awesome icon? I’ve tried to replace the text to but it doesn’t work.

    Hope to hear soon!

    1. This may be possible, but not if the HTML of the text is removed by another filter or function.

  10. Perfect! Thank you. Very easy.

  11. Nope, not working.

    1. The snippet should now be fixed.

  12. Good Samartian was and is correct. The single quotes used in this page were curly quotes and that breaks the PHP coding.

    I used Windows Notepad and replaced the curly quotes with single straight quotes, keyboard key ‘

    Curly quotes are not standard to English keyboards, either single or double straight quote characters are standard to the keyboard. So why the author, Debjit Saha, used curly quotes for us to copy is beyond me and he/she hasn’t even returned to correct this error.

    Here is the PHP code with the correct quotes:

    add_filter(‘woocommerce_product_single_add_to_cart_text’, ‘woo_custom_cart_button_text’);

    function woo_custom_cart_button_text() {
    return __(‘Book Now’, ‘woocommerce’);
    }

  13. Good Samaritan abril 11, 2019 en 9:06 am

    Dude, change the apostrophe from ‘ to ‘, as in ENGLISH it’s not used and it breaks the code.

    1. That’s worked for me.
      I write code again with the help of keyboard and its working now.

      Thanks.

  14. joseph Tersoo abril 5, 2019 en 9:16 pm

    I tried this code on my site but the Code doesnt work for me here is the working code you can try it out:
    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' );

    }

  15. add_filter( ‘woocommerce_product_single_add_to_cart_text’ , ‘woo_custom_cart_button_text’ );

    function woo_custom_cart_button_text() {
    return __(‘Adauga in cos’ , ‘woocommerce’);
    }

    This is how it works. Tried everything up there. Nothing worked for me.

  16. // Changing Add to Cart button text to custom text in individual product pages
    function woo_custom_cart_button_text()
    {
    return __(‘Add Item’, ‘woocommerce’);
    }
    add_filter(‘woocommerce_product_single_add_to_cart_text’, ‘woo_custom_cart_button_text’);

    // Changing Add to Cart button text to custom text in product archive/listing pages
    function woo_custom_product_add_to_cart_text() {
    return __( ‘Add Item’, ‘woocommerce’ );
    }
    add_filter( ‘woocommerce_product_add_to_cart_text’, ‘woo_custom_product_add_to_cart_text’ );

    1. Thank you Pavan Yogi, your answer was the one that worked for me.

    2. Thanks Pavan Yogi, your solution worked for me too.

    3. Thank you! This code worked for me.

  17. What if I want to add some HTML to my button label (a span tag to display an icon)? I tried but the HTML is printed straight, not “rendered”.

  18. Doesn’t work. Any other suggestions?

  19. I don’t suppose anyone knows how to change the text on the ‘Log in’ and ‘Register’ buttons on Woocommece?

  20. For those having problems and it not working try this –

    add_filter(‘woocommerce_product_single_add_to_cart_text’, ‘woo_custom_cart_button_text’);

    function woo_custom_cart_button_text() {
    return __(‘Book Now’, ‘woocommerce’);
    }

    1. This is the right one! But the ” ‘ ” is wrong, should be

      add_filter(‘woocommerce_product_single_add_to_cart_text’, ‘woo_custom_cart_button_text’);

      function woo_custom_cart_button_text() {
      return __(‘Book Now’, ‘woocommerce’);
      }

    2. It worked after correcting quotes. Thanks a lot!

  21. this is not working , i tried it .

  22. Hmmm, added this to my child theme on the customs function php section & my button text did not change??

    add_filter(‘single_add_to_cart_text’, ‘woo_custom_cart_button_text’);

    function woo_custom_cart_button_text() {
    return __(‘Add to Bag’, ‘woocommerce’);
    }

  23. Hi Saha,

    thanks for your article. I want to change the change the last button in the checkout `Buy now` or `Pay now`(Sorry I don’t know the right text in english).

    do you have any tip for that?

    1. write to your functions.php in your theme folder:
      add_filter(‘single_add_to_cart_text’, ‘woo_custom_cart_button_text’);

      function woo_custom_cart_button_text() {
      return __(‘Buy now’, ‘woocommerce’);
      }

Añadir un comentario

Nos alegra que haya decidido dejar un comentario. Tenga en cuenta que todos los comentarios se moderan de acuerdo con nuestra política de privacidad , y que todos los enlaces son nofollow. NO utilice palabras clave en el campo del nombre. Tengamos una conversación personal y significativa.

WordPress Launch Checklist

La lista definitiva para lanzar WordPress

Hemos recopilado todos los elementos esenciales de la lista de comprobación para el lanzamiento de su próximo sitio web de WordPress en un práctico ebook.
Sí, envíeme el ¡gratuito!