0

I am currently using woocommerce_after_shop_loop_item which creates an add to cart button. I have an input box with + and - to select a custom amount of products. Is there anyway of taking an amount from an input box and padding it into this function to add a custom amount of products at once?

The cart code hooked in is as follows:

global $product;

echo apply_filters( 'woocommerce_loop_add_to_cart_link',
    sprintf( '<a rel="nofollow" href="%s" data-quantity="%s" data-product_id="%s" data-product_sku="%s" class="%s">%s</a>',
        esc_url( $product->add_to_cart_url() ),
        esc_attr( isset( $quantity ) ? $quantity : 1 ),
        esc_attr( $product->get_id() ),
        esc_attr( $product->get_sku() ),
        esc_attr( isset( $class ) ? $class : 'button' ),
        esc_html( $product->add_to_cart_text() )
    ),
$product );

This is directly from the Woocommerce plugin

  • Please include code for the "Add to Cart" button, so we can see what have you done and how can we extend that to help you add quantity to cart. – Junaid Jul 3 '17 at 7:19
  • Thank you I have added the code above. I really want to know if I can pass a parameter to woocommerce_after_shop_loop_item or similar to add more than one item to the cart – JoshRicha Jul 3 '17 at 7:29
  • I almost have the solution for you but just want to know the output of $product->add_to_cart_url(). Just share a sample url of any product – Junaid Jul 3 '17 at 7:34
  • Sorry, I didn't notice "This is directly from the Woocommerce plugin". This means you don't have control over the code above, I mean you shouldn't edit that. Alternatively, I can help you acomplish this with JS if you could include HTML output of any product, I need to see the Quantity Up/Down and this Add To Cart anchor tag in action – Junaid Jul 3 '17 at 7:37
  • Sure. It currently adds via AJAX and the URL is: code<a rel="nofollow" href="/helenshillwp/shop/?removed_item=1&amp;add-to-cart=1887" data-quantity="1" data-product_id="1887" data-product_sku="" class="button product_type_simple add_to_cart_button ajax_add_to_cart">Add to cart</a>code – JoshRicha Jul 3 '17 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.