Support » Plugin: WooCommerce » How to change “You cannot add another” message

  • Resolved pinksharpii

    (@pinksharpii)


    I want to change the sold individually error message when someone tries to add a product to their cart twice. The code just throws an exception and it does not look like we are allowed to change this message…

    throw new Exception( sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', wc_get_cart_url(), __( 'View cart', 'woocommerce' ), sprintf( __( 'You cannot add another "%s" to your cart.', 'woocommerce' ), $product_data->get_name() ) ) );

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi there!

    How are you changing the message — are you using a custom function?

    Wouldn’t it be easier for you to use a free translation plugin like Loco Translate (https://wordpress.org/plugins/loco-translate/). I know it may sound strange to “translate” your own language, but it works.

    Here’s what you’ll need to do once you’ve installed and activated the plugin:

    1. From the administration sidebar, click on “Loco Translate” option and click on “Plugins”.
    2. Select the WooCommerce plugin from the list.
    3. Choose the option “New Language”.
    4. Select the current language for your site (if you’re using an English version of WordPress, use English, etc.)
    5. Find the strings that you want to change with the filter box.
    6. In the second box on the left, add your replacement texts.
    7. Save your changes and reload your site.

    Here’s a video about it that outlines how it is used: https://www.youtube.com/watch?v=ZUPhsoUm-QE

    Say What?
    https://wordpress.org/plugins/say-what/
    may be able to do it but without the overhead of maintaining a custom translation.

    Is this not possible to fix without some plugin? Will a plugin even help with this? I’m not changing a fixed phrase – it’s dynamic. So I don’t understand how those will help.

    Either method will handle dynamic messages. The %s placeholder is used in the translated string so the software can insert the dynamic product name in the right place.

    Plugin Support Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Howdy!

    We haven’t heard back from you in a while, so I’m going to go ahead and mark this thread as resolved. If you have any other questions please start a new thread.

    Cheers!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to change “You cannot add another” message’ is closed to new replies.