Menu Close

WooCommerce: Add “Quantity” Label in front of Add to Cart Button

default

Here’s another little WooCommerce tweak for your website user experience: let’s add some text in front of the Add to Cart button that says “Quantity: “.

As usual, we go looking for the right “hook”… the WooCommerce plugin is full of them and adding some custom content in the exact position we want is very easy. Enjoy!

Add “quantity” label before Add to Cart @ Single Product Page

PHP Snippet: Add “Quantity” Label in front of Add to Cart Button – WooCommerce

/**
 * @snippet       Add "Quantity:" before Add to Cart Button - WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 8
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_action( 'woocommerce_before_add_to_cart_quantity', 'bbloomer_echo_qty_front_add_cart' );

function bbloomer_echo_qty_front_add_cart() {
	global $product;
	if ( $product->get_min_purchase_quantity() == $product->get_max_purchase_quantity() ) return;
 	echo '<div class="qty">Quantity: </div>'; 
}

And a couple of CSS lines as well:

div.qty {
    float: left;
    padding: 10px;
}
View Source
Posted in WooCommerce Tips