• Resolved CarlVarsh

    (@carlo12teca)


    Hi!

    I put in functions.php this code to change the label of the “add to cart” button. Here is the code:

    add_filter( 'woocommerce_product_add_to_cart_text', 'nlwc_custom_button_text' );
    
    function nlwc_custom_button_text() {
    	return __('Aggiungi ');
    }

    Is this solution able to be translated with Poedit(for example)?

    I tried to insert <?php _e(‘Aggiungi’, ‘theme’); ?> instead of AGGIUNGI, but I received a critical error.

    How can I do to be able to translate the button add to cart in my theme?

    Thanks a lot
    Carlo

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support RK a11n

    (@riaanknoetze)

    Hi there,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Thread Starter CarlVarsh

    (@carlo12teca)

    Ok thanks for the links!

    Just a recap there was a little error in my text, this is the code I tried:
    <?php e_(‘Aggiungi’, ‘theme’); ?>

    Plugin Support Stuart Duff – a11n

    (@stuartduff)

    Automattic Happiness Engineer

    Hey @carlo12teca,

    Is there a particular reason you’re adding this code to your site as the Add To Cart buttons within WooCommerce are fully translatable by default?

    You can tramslate text within WordPress plugins and themes by using a free translation plugin like Loco Translate.

    Thread Starter CarlVarsh

    (@carlo12teca)

    Hi @stuartduff , yes there is a reason because for now, I want to build a fake eCommerce.

    Are you sure I’ll able to translate this button with Loco Translate(I want to buy Polylang Pro to translate all the site)?

    Thanks for the comment:)
    Carlo

    Plugin Support AW a11n

    (@slash1andy)

    Automattic Happiness Engineer

    The string there is completely translate ready. You can translate it using any of the standard methods for translating text in a WordPress site.

    Thread Starter CarlVarsh

    (@carlo12teca)

    Hi @slash1andy if I insert _e instead of __ now the term is translatable, but I have a bug because in the output code the word is separated from the button.

    function nlwc_custom_button_text() {
    	return _e('Show more ', 'theme');
    }

    I have a screenshot about it, but I don’t find how I can post it.

    • This reply was modified 4 years, 1 month ago by CarlVarsh.
    Thread Starter CarlVarsh

    (@carlo12teca)

    Hi guys, I’m so happy because I find the solution

    function nlwc_custom_button_text() {
    	return esc_html__('Show more ', 'theme');
    }

    Now is translatable!:)

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Change text button “add to cart” able to translation’ is closed to new replies.