Min Max Default Quantity for WooCommerce issue when stock is below minimum

136 Views Asked by At

We use Min Max Default Quantity for WooCommerce plugin to make customers buy our products in minimum quantities with set increments for some items.
The plugin allows customers to buy less than the minimum if the total remaining stock quantity is below the set minimum.

The only problem is the default quantity still populates in the qty field, and many customers do not realize they can change it. We need a way to change the default quantity to the stock quantity once it falls below the set minimum.

add_filter( 'woocommerce_quantity_input_args', 'woocommerce_quantity_input_args', 10, 2 );

function woocommerce_quantity_input_args( $args, $product ) {
    $stock_qty = $product->get_stock_quantity();
    $alg_wc_pq_minimum = get_post_meta( $product->get_id() , '_alg_wc_pq_minimum', true );
    
    if($stock_qty < $alg_wc_pq_minimum) {
        return $args;
    }
    
    if( get_post_meta( $product->get_id() , '_alg_wc_pq_default', true ) && '-1' != get_post_meta( $product->get_id() , '_alg_wc_pq_default', true ) && is_cart() == false) {
        $args['input_value'] = get_post_meta( $product->get_id() , '_alg_wc_pq_default', true );
    }
    
    return $args;
}

Here's what we tried, but the default quantity isn't changing.

0

There are 0 best solutions below