How To: Remove Product Quantity Selectors – WooCommerce

Advertisement

Another snippet that I’ve found useful, is by removing product quantity selectors in WooCommerce, this is rare to happen but mostly in products that are too expensive that you can’t even hold your mouse and click the “add to cart” button, so in that case we better take the quantity selector off, don’t worry by default it added single item into your cart.

Let’s get started

Code


/**
 * @desc Option to where you only want the quantity selector to display
 */
add_filter( 'woocommerce_is_sold_individually', 'wc_remove_all_quantity_fields', 10, 2 );
function wc_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;
}

Hide in all product type


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

That’s it, Happy Coding ^_^

Advertisement