php - Remove the stock quantity from WooCommerce cart error messages -


iin woocommerce, i've set woocommerce->settings->products->inventory->stock display format "never show quantity remaining in stock".

however if customer ads product cart, continues cart or checkout page , enter value higher have in stock error message:

sorry, not have enough "{product_name}" in stock fulfill order ({available_stock_amount} in stock). please edit cart , try again. apologize inconvenience caused.

what filter can use edit output? don't want show (absolutely anywhere on front end shop) actual available stock amount.

i've found handled in function (check_cart_item_stock) in, [root]->wp-content->plugins->woocommerce->includes->class-wc-cart.php on line 491:

if ( ! $product->has_enough_stock( $product_qty_in_cart[ $product->get_stock_managed_by_id() ] ) ) {     /* translators: 1: product name 2: quantity in stock */     $error->add( 'out-of-stock', sprintf( __( 'sorry, not have enough "%1$s" in stock fulfill order (%2$s in stock). please edit cart , try again. apologize inconvenience caused.', 'woocommerce' ), $product->get_name(), wc_format_stock_quantity_for_display( $product->get_stock_quantity(), $product ) ) );     return $error; } 

so want filter out "(%2$s in stock)" part. can't find filter this.

thank @loictheaztec reply, found filter after all, woocommerce_add_error

so final filter (in functions.php) this:

function remove_stock_info_error($error){     global $woocommerce;     foreach ($woocommerce->cart->cart_contents $item) {         $product_id = isset($item['variation_id']) ? $item['variation_id'] : $item['product_id'];         $product = new \wc_product_factory();         $product = $product->get_product($product_id);          if ($item['quantity'] > $product->get_stock_quantity()){             $name = $product->get_name();             $error = 'sorry, not have enough "'.$name.'" in stock fulfill order. please edit cart , try again. apologize inconvenience caused.';             return $error;         }     } }add_filter( 'woocommerce_add_error', 'remove_stock_info_error' ); 

this should resolve across board.

note! found input boxes have max attribut, in turn means can still see actual total available amount (by either using built in increment (which stop when reaching max value) or enter high of value, click update cart , notice amount has equal or less x (max value)).

to combat added simple js in pre-existing "woo-xtra.js":

var qty             = $('form.woocommerce-cart-form').find('input.qty'); // reset max value quantity input box hide real stock qty.attr('max', ''); 

this way there no max value, user still error (if on limit) above :)

i.e. problem solved


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -