0

I manage product inventory by manually entering the stock. When I have 2 in stock, but a guest adds 3 to their cart, WooCommerce shows the following error message:

enter image description here

I have located the code for this error message in the following file: woocommerce/includes/class-wc-cart.php.

I made an attempt to copy this file into the following location in my child theme: mytheme/woocommerce/templates/includes/class-wc-cart.php. I then edited the message within the copy, and clicked save, thinking it would work. Instead, it broke my site (good think I'm using an FTP client, so I quickly reverted).

What am I doing wrong here? Is there a step I am missing in order to change this message? I thought simply copying it to my child theme would overwrite the original file as provided by WooCommerce.

Thank you, R

1 Answer 1

1

You have placed the new file in the incorrect folder location. The woocommerce folder in your child-theme should not contain 'templates'. Use the following directory: mytheme/woocommerce/includes/class-wc-cart.php

You can also edit this text by adding a filter https://stackoverflow.com/questions/23064185/woocommerce-changing-the-in-stock-text

3
  • 1
    Thanks! Realized you can only override template files, not class files. This is the code where the message is coming from: if ( ! $_product->has_enough_stock( $check_qty ) ) { $error->add( 'out-of-stock', sprintf(__( 'Sorry, we do not have enough "%s" in stock to fulfill your order (%s in stock). Please edit your cart and try again. We apologise for any inconvenience caused.', 'woocommerce' ), $_product->get_title(), $_product->get_stock_quantity() ) ); return $error; } How do I add a filter that changes this message?
    – SWAP
    Commented Feb 22, 2016 at 0:19
  • Look at the link attached in my answer. Place it in your theme/child-themes function.php file
    – bkcol
    Commented Feb 24, 2016 at 1:35
  • 1
    Thanks but that isn't the text that I am trying to change. I'm trying to change the error message above the cart, not the "out of stock" that appears next to the product in the catalog.
    – SWAP
    Commented Feb 28, 2016 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.