X
    Categories: WooCommerce Tutorials, Tips and GuidesWordPress Tutorials, Tips and Guides

Easily Hide Product Quantity Field From WooCommerce Product Pages

Reading Time: 2 minutes

WooCommerce is a great platform for ecommerce stores simply because of the many features and customization options. In many cases, developers could customize the store exactly to the requirements of the business model.

There are cases where WooCommerce is used to create bulk order store that deal in fixed order sizes. In other cases, the store just deal in a single physical or digital product. In both cases, the field of Item Quantity becomes extraneous. The best strategy in this scenario is to remove the field completely from the page.

Fortunately, WooCommerce provides a filter to remove this field from the store. All you have to do is to paste the following code in the functions.php of the installed theme.   

function quantity_wp_head() {
   
if ( is_product() ) {
    ?>
<style type="text/css">.quantity, .buttons_added { width:0; height:0; display: none; visibility: hidden; }</style>
<?php
    }
}
    add_action( 'wp_head', 'quantity_wp_head' );

 

Hide Particular Type of Product

Another scenario is when the store owners need to remove a particular type of product from the item order page. For this, just add the following code to the functions.php of the theme:

add_filter( 'woocommerce_is_sold_individually', 'cw_remove_quantity_fields');
function cw_remove_quantity_fields( $return, $product ) {
switch ( $product->product_type ) :

case "grouped":
return true;
break;
case "external":
return true;
break;
case "variable":
return true;
break;
default:
return true;
break;
endswitch;
}

 

Here is how this code would change the page:

Hide From All Product Type

If you wish to hide the quantity field completely for all products, add the following snippet to the functions.php:

function cw_remove_quantity_fields( $return, $product ) {
    return true;
}
add_filter( 'woocommerce_is_sold_individually', 'cw_remove_quantity_fields', 10, 2 );

 

Conclusion

In this short tutorial, I demonstrate how you could remove the order quantity field from the product page. All it takes is an addition of simple code snippets to the functions.php file. If you need help, just drop a comment below and I will get back to you.

 

Owais Alam :is the WordPress Community Manager at Cloudways - A Managed WooCommerce Hosting Platform and a seasoned PHP developer. He loves to develop all sorts of websites on WordPress and is in love with WooCommerce in particular. You can email him at owais.alam@cloudways.com