Skip to content

Instantly share code, notes, and snippets.

@spiderflystudios
Last active September 26, 2015 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spiderflystudios/19e3463eeb97213c2cdb to your computer and use it in GitHub Desktop.
Save spiderflystudios/19e3463eeb97213c2cdb to your computer and use it in GitHub Desktop.
Woocommerce - Display max quantity allowed if set on a product
// display max quantity allowed if set on single product page
add_action('woocommerce_single_product_summary', 'maxquantityallowed', 30);
function maxquantityallowed() {
if(get_post_meta( get_the_ID(), 'maximum_allowed_quantity', true ) ){
echo 'Maximum quantity allowed for this product is <strong>'. get_post_meta( get_the_ID(), 'maximum_allowed_quantity', true ) .'</strong>. Request a custom quote for bulk orders.'; }
}
// hide quantity box if max quantity is set to one
add_action('wp_head','hide_quantity_counter');
function hide_quantity_counter() {
global $product;
$product = new WC_Product( get_the_ID() );
$productcount = get_post_meta( get_the_ID(), 'maximum_allowed_quantity', true );
// adjust for different product types
if (($product->is_type( 'bundle' )) || $productcount == 1) { echo '<style> div.bundled_item_cart_content div.bundle_button div.quantity {display:none!important;} </style>'; }
if (($product->is_type( 'simple' )) || $productcount == 1) { echo '<style> div.quantity {display:none!important;} div.bundled_product div.quantity {display:inherit!important;} </style>'; }
if (($product->is_type( 'variable' )) || $productcount == 1) { echo '<style> div.variations_button div.quantity {display:none!important;} div.bundled_product div.variations_button div.quantity {display:inherit!important;} </style>'; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment