Skip to content

Instantly share code, notes, and snippets.

@muks999
Forked from SJ-James/limit-low-stock-woo.php
Created January 6, 2018 17:40
Show Gist options
  • Save muks999/4f3a4ccd3827cf36ba7a86f49e0a91f9 to your computer and use it in GitHub Desktop.
Save muks999/4f3a4ccd3827cf36ba7a86f49e0a91f9 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