Support » Plugin: Quantity Field on Shop Page for WooCommerce » No max on quantity field

  • Hi!
    The quantity field doesn’t have MAX set. For example if you use stock and you have 3 products in stock you can add 4, 5 or more.

    I needed the plugin for a client i made some quick changes so i can use it.

    I just added before “return $html; ”

    $html = str_replace('max=""','max='.$product->stock_quantity,$html);

    The plugin works fine this is the only problem. Good work! Thank you.

    `public function woa_add_quantity_fields($html, $product) {

    //add quantity field only to simple products
    if ( $product && $product->is_type( ‘simple’ ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
    //rewrite form code for add to cart button
    $html = ‘<form action=”‘ . esc_url( $product->add_to_cart_url() ) . ‘” class=”cart” method=”post” enctype=”multipart/form-data”>’;
    $html .= woocommerce_quantity_input( array(), $product, false );
    $html .= ‘<button type=”submit” data-quantity=”1″ data-product_id=”‘ . $product->id . ‘” class=”button alt ajax_add_to_cart add_to_cart_button product_type_simple”>’ . esc_html( $product->add_to_cart_text() ) . ‘</button>’;
    $html .= ‘</form>’;

    }

    <strong> $html = str_replace(‘max=””‘,’max=’.$product->stock_quantity,$html);</strong>

    return $html;
    }`

    • This topic was modified 3 years, 6 months ago by pressjockey.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘No max on quantity field’ is closed to new replies.