1

With woocommerce enabled, we sell wine on our e-shop.

I would like an additional button so that customer can buy a case of wine (12 bottles) rather than having to select qty= 12.

I would like to stick the button after the 'add to cart' button on each single product page.

Until now I can't find exactly the way to do it.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Hello Stephanie … I have an answer for an additional quantity input field related to that "Add a case of 12" … Each step in this additional quantity input field will add a case of 12… So if quantity is 1 => 12 … if quantity is 2 => 24 … and so on. If you are interested in that contact me though my profile linked email form. Then we will sync us to make that happen. – LoicTheAztec Mar 25 '18 at 06:19

2 Answers2

6

It can be done easily with a custom hooked function displaying an additional button that will add 12 products on 1 click on single product pages for simple products only:

add_action( 'woocommerce_after_add_to_cart_button', 'additional_simple_add_to_cart', 20 );
function additional_simple_add_to_cart() {
    global $product;

    // Only for simple product type
    if( ! $product->is_type('simple') ) return;

    $href = '?add-to-cart=' . esc_attr( $product->get_id() ) . '&quantity=12';
    $class = 'ingle_add_to_cart_button-12 button alt';
    $style = 'display: inline-block; margin-top: 12px;';
    $button_text = __( "Add a case of 12", "woocommerce" );

    // Output
    echo '<br><a rel="no-follow" href="'.$href.'" class="'.$class.'" style="'.$style.'">'.$button_text.'</a>';
}

Code goes in function.php file of your active child theme (active theme).

Tested and works.

enter image description here

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
0

this is a help site designed for coders that hit a wall, not really a substitute for using quick google search and the many free pages and tutorials on managing and tweaking such a popular third party platform.

For example, searching google for "woocommerce custom add to cart button" showed how to affect the urls and text, and a search for "woocommerce add custom button" showed how to add extra ui buttons in various pages.

And as others posted here, there also appears to be many plugins making that even simpler, a few of which show up in those searches i listed above, such as "min/max quantity"

https://wordpress.org/plugins/woo-min-max-quantity-limit/

https://wordpress.org/plugins/minmax-quantity-for-woocommerce/

Please see https://stackoverflow.com/help/how-to-ask if you try implementing those, hit a wall and cant find anything (after searching for a while) to work around it.

Hope that helps too

Daniel Brose
  • 1,394
  • 10
  • 24