-
-
Save muks999/4f3a4ccd3827cf36ba7a86f49e0a91f9 to your computer and use it in GitHub Desktop.
Limit Quantity for low stock items
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
<?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