Last active
September 26, 2015 17:22
-
-
Save spiderflystudios/19e3463eeb97213c2cdb to your computer and use it in GitHub Desktop.
Woocommerce - Display max quantity allowed if set on a product
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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.'; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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