Home Forums WoodMart support forum Plus and minus for ajax add to cart

Plus and minus for ajax add to cart

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #64009

    mohamad akram
    Participant

    Hello,

    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

    #64024

    Artem Temos
    Keymaster

    Hi,

    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

    #64037

    mohamad akram
    Participant

    Ok 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?

    #64047

    Artem Temos
    Keymaster

    Unfortunately, there is no such functionality in our theme and WooCommerce plugin by default.

Viewing 4 posts - 1 through 4 (of 4 total)