Skip to content

Instantly share code, notes, and snippets.

@SJ-James
Created January 4, 2018 19:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SJ-James/67daecfd2a490c0ccfba9a929dff8ec4 to your computer and use it in GitHub Desktop.
Save SJ-James/67daecfd2a490c0ccfba9a929dff8ec4 to your computer and use it in GitHub Desktop.
Limit Quantity for low stock items
<?php
function limit_wc_stock() {
global $product;
if ( $product->stock ) {
if ( number_format($product->stock,0,'','') < 100 ) { // If stock is less than 100
/* Limit Quantity */
function limit_wc_stock_quantity_args( $args, $product ) {
$args['max_value'] = 10; // Max value
return $args;
}
}
}
}
add_action('woocommerce_after_shop_loop_item','limit_wc_stock', 10);
add_filter( 'woocommerce_quantity_input_args', 'limit_wc_stock_quantity_args', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment