Home › Forums › WoodMart support forum › Plus and minus for ajax add to cart
Plus and minus for ajax add to cart
- This topic has 3 replies, 2 voices, and was last updated 5 years, 9 months ago by Artem Temos.
-
AuthorPosts
-
June 21, 2018 at 7:11 am #64009
mohamad akramParticipantHello,
im trying to make + and – buttons for products in home and category pages so i made some changes in add-to-cart.php
<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="cart" method="post" enctype="multipart/form-data"> <?php ?> <div class="quantity"> <input onclick="reply_click(this.id)" type="button" id="<?php echo $product->id; ?>" value="-" class="minus"> <label class="screen-reader-text" for="quantity_<?php echo $product->id; ?>">Quantity</label> <input type="number" id="quantity_<?php echo $product->id; ?>" class="input-text qty text" step="1" min="1" max="" name="quantity" value="1" title="Qty" size="4" pattern="[0-9]*" inputmode="numeric" aria-labelledby=""> <input onclick="reply_click2(this.id)" type="button" value="+" id="<?php echo $product->id; ?>" class="plus"> </div> <?php // Display the submit buttonecho "alert('$args['s']')"; echo apply_filters( 'woocommerce_loop_add_to_cart_link', sprintf( '<a id=prod_'.$product->id .' href="%s" data-quantity="1" class="%s cart-cart add-to-cart-loop" %s><span>%s</span></a>', esc_url( $product->add_to_cart_url() ), esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ), isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '', esc_html( $product->add_to_cart_text() ) ), $product, $args ); ?> </form> <?php } else { echo apply_filters( 'woocommerce_loop_add_to_cart_link', sprintf('<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="%s button product_type_%s">%s</a>', esc_url( $link['url'] ), esc_attr( $product->id ), esc_attr( $product->get_sku() ), esc_attr( $link['class'] ), esc_attr( $product->product_type ), esc_html( $link['label'] ) ), $product, $link ); }
here is the code
i made a custom id for every product and i make a js function:function reply_click(clicked_id) {var ww = "prod_"+clicked_id; var x= document.getElementById(ww); var r2 = x.getAttribute("data-quantity"); var m = parseInt(r2); if(m>2) { var q = m -1; } var r = x.setAttribute("data-quantity", q ); } function reply_click2(clicked_id) { var ww = "prod_"+clicked_id; var x= document.getElementById(ww); var r2 = x.getAttribute("data-quantity"); var m = parseInt(r2); var q = m + 1; var r = x.setAttribute("data-quantity", q ); }
to change the data-quantity for every product ,
every thing worked find except the last two items i added in the store,i cant find the problem!
is there a solution? and is there any way to make + and – buttons for script add to cart?please help
June 21, 2018 at 7:53 am #64024
Artem TemosKeymasterHi,
Sorry, but this question is related to additional code customization and the snippet you sent is not related to our theme. We can’t know why it doesn’t work for you.
Regards
June 21, 2018 at 8:14 am #64037
mohamad akramParticipantOk thanks, do you have in the theme any option to add plus and minus for ajax add to cart in home page?
if not, i really need it what should i do to get it?June 21, 2018 at 9:33 am #64047
Artem TemosKeymasterUnfortunately, there is no such functionality in our theme and WooCommerce plugin by default.
-
AuthorPosts
Tagged: WOODMART add-to-cart
- You must be logged in to create new topics. Login / Register