• Resolved sandyfootprints

    (@sandyfootprints)


    Hi

    I have tried to install a plugin to enable quantity plus and minus buttons on the quantity field and, whilst it works on the individual product page, it doesn’t work in the product table. I have also tried to use some code in functions.php which also doesn’t work. Please could you advise? The function is below:

    add_action( 'woocommerce_after_add_to_cart_quantity', 'ts_quantity_plus_sign' );
     
    function ts_quantity_plus_sign() {
       echo '<button type="button" class="plus" >+</button>';
    }
     
    add_action( 'woocommerce_before_add_to_cart_quantity', 'ts_quantity_minus_sign' );
    function ts_quantity_minus_sign() {
       echo '<button type="button" class="minus" >-</button>';
    }
     
    add_action( 'wp_footer', 'ts_quantity_plus_minus' );
     
    function ts_quantity_plus_minus() {
       // To run this on the single product page
       if ( ! is_product() ) return;
       ?>
       <script type="text/javascript">
              
          jQuery(document).ready(function($){   
              
                $('form.cart').on( 'click', 'button.plus, button.minus', function() {
     
                // Get current quantity values
                var qty = $( this ).closest( 'form.cart' ).find( '.qty' );
                var val   = parseFloat(qty.val());
                var max = parseFloat(qty.attr( 'max' ));
                var min = parseFloat(qty.attr( 'min' ));
                var step = parseFloat(qty.attr( 'step' ));
     
                // Change the value if plus or minus
                if ( $( this ).is( '.plus' ) ) {
                   if ( max && ( max <= val ) ) {
                      qty.val( max );
                   } 
                else {
                   qty.val( val + step );
                     }
                } 
                else {
                   if ( min && ( min >= val ) ) {
                      qty.val( min );
                   } 
                   else if ( val > 1 ) {
                      qty.val( val - step );
                   }
                }
                 
             });
              
          });
              
       </script>
       <?php
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author WC Product Table

    (@wcproducttable)

    Hi,

    Thank you for writing in with your query.

    The script / plugins you add to your site to create quantity + / – controls are only designed to work on the single product page. They are not related to the product table. That is a completely different system.

    WooCommerce Product Table PRO, the premium version of this plugin offers a facility to add + / – controls on the table’s Quantity element. You can add the + / – controls on both edges of the input box, or just left or right edge.

    – In this WCPT PRO demo the Quantity element has + / – controls on both edges

    – In this WCPT PRO demo the Quantity element has the controls only on the left edge.

    As you can see in the PRO demos it also lets you set initial quantity to empty or 0. In fact it offers dozens of additional exclusive facilities.

    You can check out the WCPT PRO facilities here.

    I hope this answers your question but please feel free to write in if there is anything else.

    Regards,
    Kartik

    Plugin Author WC Product Table

    (@wcproducttable)

    Hi,

    Since I have not heard back from you on this topic for a couple of weeks, I am assuming your question is resolved. So I am closing this topic.

    Please feel free to write in if you have any further questions about WooCommerce Product Table.

    Regards,
    Kartik

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using quantity plus minus buttons instead of number field’ is closed to new replies.