Modify Maximum Quantity for WooCommerce Products for Woo Sell Services
vapvarun |
PRO |
12/06/23 11:33:16 AM UTC |
0 ⭐ |
1326 👁️ |
Never ⏰ |
[woocommerce, Woo Sell Services]
/**
* Modify Maximum Quantity for WooCommerce Products
*
* This code snippet is used to adjust the maximum quantity input for WooCommerce products.
* Specifically, it targets products marked as a service or non-tangible item.
*/
// Add a filter to modify the maximum quantity input for WooCommerce products
add_filter( 'woocommerce_quantity_input_max', 'woo_sell_service_test_quantity_input_max', 20, 2 );
/**
* Function to set the maximum quantity for service-type products
*
* @param int $max_value The maximum quantity value.
* @param WC_Product $product The product object.
* @return int The modified maximum quantity value.
*/
function woo_sell_service_test_quantity_input_max( $max_value, $product ) {
// Check if the product is marked as a service or non-tangible item
if ( 'yes' == get_post_meta( $product->get_id(), '_wss_type', true ) ) {
// Ensure the product is not sold individually by clearing the '_sold_individually' meta
update_post_meta( $product->get_id(), '_sold_individually', '' );
}
// Return the maximum quantity value (modified or unmodified)
return $max_value;
}
Comments