• All the plugins I try to do this with seem to fail including this one. What I need is to automatically add the default quantity I want when Add to Cart is clicked (in this case, a qty of 2) right away to the cart (from either a product archive page OR a single product page).

    For most users, we don’t even want to show them the quantity in the Cart page, just force it to be 2. (Already using CSS to do this.) When you get to the cart, it DOES say 2, but the quantity field actually has a value=”1″ and min=”2″ – and when you proceed to checkout, you get a qty only of 1. (We do not want most users to update their cart with the button, which we will also be hiding–presumably Update Cart would then update to the 2).

    I just can’t seem to find any answers, anywhere. We’re trying to launch next week!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @llupien,

    I am sorry to hear it. It might be a setup issue. I would suggest to reset the plugin’s settings first and follow the configuration below:

    1. Please go to the “Minimum Quantity” section of the plugin, and set the “All products” option to “2”,
    2. Then go to the “Maximum Quantity” section and set the “All products” option to “2” as well,

    After that, the plugin will remove the standard input field from the single product page and from the cart page and force users to add two products to the cart when they click on the “Add to Cart” button.

    Kind regards.

    Thread Starter llupien

    (@llupien)

    With further troubleshooting I’ve determined it’s the custom child theme that a previous developer had put in place (a child of Themify Shoppe). They were producing a “link” for a button for Add to Cart, somehow that was not working with default quantity. I am overriding whatever they did by putting the base function WooCommerce suggested into the child theme functions.php which adds a form with button instead of just a link (had to restyle the default button CSS again but that’s easy). Then for the user group in question, I’m just hiding the quantity field with CSS, as I’ve already added a function to put the User Role into the body tag. (This also gives Admins access to a qty field in the Product Archive page, as they will be doing custom purchases of more than 2 in certain circumstances, making their job easier!)

    /**
    * Override loop template and show quantities next to add to cart buttons
    */
    
    add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
    
    function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) {
    
    ????if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
    
    ????????$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" class="button product_type_simple add_to_cart_button ajax_add_to_cart">' . esc_html( $product->add_to_cart_text() ) . '</button>';
    
    ????????$html .= '</form>';
    
    ????}
    
    ????return $html;
    
    }

    Adding this solution here for anyone who encounters the same issue.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add to Cart only does qty 1; need to automatically add 2 to cart’ is closed to new replies.