Bulk buy buttons on shop page - by metrophanes

This topic has 5 replies, 2 voices, and was last updated 8 years, 6 months ago ago by Eva Kemp

  • Avatar: metrophanes
    metrophanes
    Participant
    November 5, 2015 at 20:59

    Hello there!

    I’m using WooCommerce and Legenda using my own child theme.

    I’m trying to make 2 buy buttons for every product on the shop page.
    Button 1 quantity = 1
    Button 2 quantity = 6

    In woocommerce/loop/add-to-cart.php my code looks like this:

    
    if(etheme_get_option('ajax_addtocart') && $product->is_purchasable()) {
    	$class .= 'etheme_add_to_cart_button ';
    }
    
    echo apply_filters( 'woocommerce_loop_add_to_cart_link',
    	sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" data-quantity="%s" class="button %s product_type_%s">1 stk.</a>',
    		esc_url( $product->add_to_cart_url() ),
    		esc_attr( $product->id ),
    		esc_attr( $product->get_sku() ),
    		esc_attr( isset( $quantity ) ? $quantity : 1 ),
    		$class,
    		esc_attr( $product->product_type ),
    		esc_html( $product->add_to_cart_text() )
    	),
    $product );
    
    echo apply_filters( 'woocommerce_loop_add_to_cart_link',
    	sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" data-quantity="%s" class="button %s product_type_%s">6 stk.</a>',
    		esc_url( $product->add_to_cart_url() ),
    		esc_attr( $product->id ),
    		esc_attr( $product->get_sku() ),
    		esc_attr( isset( $quantity ) ? $quantity : 6 ),
    		$class,
    		esc_attr( $product->product_type ),
    		esc_html( $product->add_to_cart_text() )
    	),
    $product );
    

    When the class ‘etheme_add_to_cart_button’ is added to the button and I click it, it gives a nice animation, updates the cart but only 1 item is added to the cart.
    If changing the class to ‘add_to_cart_button’ I don’t get any animation, the cart doesn’t update, but if I manually refresh the page it gets the right amount of items.

    How do I either make it work with quantity when using the ‘etheme_add_to_cart’ class, or make the cart update when using ‘the add_to_cart’ class?

    4 Answers
    Avatar: Eva
    Eva Kemp
    Support staff
    November 6, 2015 at 17:34

    Hello,

    Please take our apologies, but this requires additional customization which is beyond our basic support scope.
    By default our theme doesn’t have features for 2 “Add to Cart” buttons.

    Regards,
    Eva Kemp.

    Avatar: metrophanes
    metrophanes
    Participant
    November 7, 2015 at 12:52

    Alright, I can understand that.

    Can you point me in the direction of where to find the function that handles the cart update?

    Avatar: metrophanes
    metrophanes
    Participant
    November 7, 2015 at 13:35

    Nvm my last question. I figured it out.

    In case anyone else is looking for the same function this is what to do:
    First off edit wp-content/themes/legenda/js/etheme.js and change line 1191 from:
    quantity: 1
    to
    quantity: $thisbutton.attr('data-quantity')

    Then edit wp-content/themes/legenda/woocommerce/loop/add-to-cart.php
    and add the attribute data-quantity to each button as so:
    sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" data-quantity="6" class="button %s product_type_%s">6</a>',

    Avatar: Eva
    Eva Kemp
    Support staff
    November 8, 2015 at 10:22

    Hello,

    Glad you’ve managed to resolve the issue.

    Have a nice day.

    Regards,
    Eva Kemp.

  • Viewing 5 results - 1 through 5 (of 5 total)

The issue related to '‘Bulk buy buttons on shop page’' has been successfully resolved, and the topic is now closed for further responses

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.