Hide the Quantity input field for specific products in WooCommerce

You can use the following code to add some custom CSS to your page which will hide the quantity input only if the product has the hide_quantity_input meta key.

To add this, you can use the Custom Fields meta box in the product edit screen. Click “Enter New” and then enter hide_quantity_input as the name and any value you wish. When you are done click Add Custom Field.

hide quantity input
<?php
function sv_hide_quantity_input() {
    $post_id = get_queried_object_id();

    if ( is_product() && metadata_exists( 'post', $post_id, 'hide_quantity_input' ) ) {
        ?>
            <style type="text/css">
                form.cart div.quantity {
                    display: none !important;
                }
            </style>
        <?php
    }
}
add_action( 'wp_head', 'sv_hide_quantity_input' );
?>

That’s it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s