• Resolved jayukey

    (@jayukey)


    Dear Sir,

    I want to implement Amazon like Quantity field behavior on my site with subtle changes. i.e.: On the product I do not want to show quantity field. There will ONLY be Add to cart button. This will allow, in case of variable product to add a product with one variation type to be added to cart. Then on the cart page I want to be able to see the ability to drop down on quantity on cart page. The drop down will need to be set. After let’s say 10 items of a certain variation of product If on product page user clicks on Add to Cart an exception should be displayed on screen. On the cart page also a max of 10 items per variation should be selected. This needs to be in sync with product page.

    Please advise.

    Thanks,
    Jayanand Ukey
    https://www.bartkart.com

    P.S. I’m using Storefront Child theme.

    https://www.ads-software.com/plugins/woocommerce/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    You could simply hide the qty button on single product pages using CSS. It will default to 1.

    Thread Starter jayukey

    (@jayukey)

    Thanks Mike for your reply. Also I want to restrict the addition to cart for a variation product when it reaches 10 quantity in cart.

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    There is a plugin called min max quantities you can use for that.

    Thread Starter jayukey

    (@jayukey)

    Actually, I would like to do it programmatically but am unable to do it for a variation product …

    Below is the code to do this for minimum qty … I want to do the opposite so in my function I want to read from cart and notify the user accordingly … for example if for a variation product of color blue there is already 5 items in cart and from product page user is adding 6 more then a notice will be sent to user that only 5 more of the blue colored variation product can be added.

    function wpbo_minimum_item_quantity_validation( $passed, $product_id, $quantity, $variation_id, $variations ) {
    // Make $woocommerce accessable
    global $woocommerce;

    // Set a minimum item quantity
    $minimum = 10;

    // Check if the quantity is less then our minimum
    if ( $quantity < $minimum ) {

    // Get the product title for the error statement
    $product = get_product( $product_id );
    $product_title = $product->post->post_title;

    // Add the error
    $woocommerce->add_error( sprintf( “You must add a minimum of %s %s’s to your cart to proceed.” , $minimum, $product_title ) );

    // If the quantity is 10 or above return true
    } else {
    return true;
    }
    }

    add_action( ‘woocommerce_add_to_cart_validation’, ‘wpbo_minimum_item_quantity_validation’, 1, 5 );

    $passed_validation = apply_filters( ‘woocommerce_add_to_cart_validation’, true, $product_id, $quantity, $variation_id, $variations );

    Thread Starter jayukey

    (@jayukey)

    I inserted code

    foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {

    in the function above so I can read what’s in cart for the variation id but I get fatal error.

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    This is exactly what the extension can handle – min/max qty per variation. You’re basically asking me to copy/paste the code from the extension? ??

    Enable WP_DEBUG to see what errors you are causing. You need to compare by variation ID to do it yourself.

    Thread Starter jayukey

    (@jayukey)

    Mike, Okay I will debug.. In the meantime can you share the link to the plugin? Thanks.

    Thread Starter jayukey

    (@jayukey)

    I believe this is the link: https://www.woothemes.com/products/minmax-quantities/

    Thanks Mike.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Implement Quantity field behavior like in Amazon’ is closed to new replies.