• I would like to change the default text of the message: “You already have this item in your cart” which happens when you have products that are sold individually. In class-wc-cart.php there is the following function:

    if ( $product_data->is_sold_individually() ) {
    	$in_cart_quantity = $cart_item_key ? $this->cart_contents[$cart_item_key]['quantity'] : 0;
    
    	// If its greater than 0, its already in the cart
    	if ( $in_cart_quantity > 0 ) {
    		$woocommerce->add_error( sprintf('<a href="%s">%s</a> %s', get_permalink(woocommerce_get_page_id('cart')), __( 'View Cart →', 'woocommerce' ), __( 'You already have this item in your cart.', 'woocommerce' ) ) );
    		return false;
    	}
    }

    As you can see the text is defined above. How would I change this text using the functions.php file?

    http://wordpress.org/extend/plugins/woocommerce/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Roy Ho

    (@splashingpixelscom)

    Based on that code snippet there are two ways. If the code is within a WooCommerce template, then you can simply copy that template to your theme’s woocommerce folder ( same structure as original ) and modify it there.

    The other way is to localize it by using the PO/MO files and translate that text.

    Thread Starter JBIRD1111

    (@jbird1111)

    The code is not within a template file – rather it is in class-wc-cart.php which is in the classes directory of the plugin.

    Im not sure what you mean by localizing it. How about using the function.php file to write a custom action / filter?

    Roy Ho

    (@splashingpixelscom)

    If it is a core file, then you need to localize/translate it. The code snippet you provided does not have any hooks so you can’t hook into it.

    Read here to learn to translate it -> http://codex.wordpress.org/Translating_WordPress

    Thread Starter JBIRD1111

    (@jbird1111)

    It seems like there has to be a better way than localization when it comes to this. Your right, there are no hooks in the snippet I provided. I personally do not know anything about localization – is the process simple? It doesn’t necessary seem like the correct way to go about this! Thoughts?

    Roy Ho

    (@splashingpixelscom)

    Unfortunately not that I know of…If there isn’t a filter, you must use translation…

    Thread Starter JBIRD1111

    (@jbird1111)

    I will read up on translating this file. I will post any questions here, thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Changing text for product add to cart error’ is closed to new replies.