Hide or remove the quantity field from WooCommerce Product

How To Disable Quantity Field In WooCommerce 800x252 - Hide or remove the quantity field from WooCommerce Product

WooCommerce is one of the best e-commerce solutions that gives you complete control to sell anything. WooCommerce’s biggest benefit is that user has nearly endless customization options to exercise with their products, without having to know too much about the technical side of things. If you want to increase the features and capabilities of your online store, you may need to install extensions or sometimes we use code snippets to customize the functionalities.

In this post, I’ve shared some code snippets to hide or remove the quantity (number of items) field from WooCommerce Product. This may require when you want your customers to order or buy only one item at a time that is disabling the ability to add or subtract quantity. Let’s find how we can hide or remove the quantity field from WooCommerce Product.

Method 1: Using Option Sold Individually in Edit Product Page

How to disable the quantity field To Sold Individually - Hide or remove the quantity field from WooCommerce Product

 

Method 2: Using WordPress built in hook or filter, When you already added lots of products

This code snippets can be used when you realize, you need to hide or remove the quantity but there are lots of products.

/** * @desc Remove in all product type */
function woo_remove_all_quantity_fields( $return, $product ) {
  return true;
}
add_filter( 'woocommerce_is_sold_individually', 'woo_remove_all_quantity_fields', 10, 2 );

 

Method 3: Hide or remove the quantity field from particular type of product

/** @Hide from different product type group */

function woo_remove_all_quantity_fields( $return, $product ) {
	switch ( $product->product_type ) :
		case "variable":
			return true;
			break;
		case "grouped":
			return true;
			break;
		case "external":
			return true;
			break;
		default: // simple product type
			return true;
			break;
	endswitch;
}

add_filter( 'woocommerce_is_sold_individually', 'woo_remove_all_quantity_fields', 10, 2 );

Warning: using this option will makes it impossible to have a product more than once in your shopping cart. Subsequently clicking on “Add to cart” button will trigger a warning that this product can be added only once in your cart.

Method 4: Hide WooCommerce quantity field using CSS

/** @Hide quantity using CSS */
function hide_quantity_using_css() {
	if ( is_product() ) {
 ?>
	<style type=3D"text/css">.quantity, .buttons_added { width:0; height:0; display: none; visibility: hidden; }</tyle>
	<?php
	}
}
add_action( 'wp_head', 'hide_quantity_using_css' );
About This Author

My name is Parameshwar Roy (P. Roy), and I am a web developer. This is my personal blog to record my own thoughts. Though I am not a natural writer, I love to share my experiences. Hope my experiences will be useful to you…read more about me

4 Comments

You can post comments in this post.


  • Thanks for the coding, where do I place these code? I only want to remove the quantity from the product page not the cart page.

    which code do i use?

    I’m very new to woocommerce

    Thank you

    Rick 5 months ago Reply


  • thanks for information, is very useful and its work

    satria 5 months ago Reply


  • Hello,

    is it possible to hide the field only from specific simple products, not all? When I add the code it is still possible to change the quantity in cart page. Any tipps :)?

    Tobias 2 weeks ago Reply


  • Thanks!

    Martins Divine 1 week ago Reply


Leave A Reply