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?