Showing posts with label Add to cart. Show all posts
Showing posts with label Add to cart. Show all posts

Monday, June 10, 2024

How to add To cart and custom Quantity Field in Woo commerce with Plus and minus button

 Quantity Box With Add to Cart button

<form class="cart" method="post" enctype="multipart/form-data">

    <div class="quantity">

        <button type="button" class="minus" >-</button>

        <input type="number" step="1" min="1" max="" name="quantity" value="1" title="Quantity" class="input-text qty text" size="4" pattern="[0-9]*" inputmode="numeric">

        <button type="button" class="plus" >+</button>

    </div>

 <input type="hidden" name="add-to-cart" value="<?php echo get_the_ID(); ?>">

<button type="submit" class="single_add_to_cart_button button alt shop-button-cart"><i class="fa fa-cart-plus" aria-hidden="true"></i> Add to cart</button>

</form>


Script to make the Minus Plus button work for Quantity box

<script>

    jQuery(document).ready(function($){

   $('form.cart').on( 'click', 'button.plus, button.minus', function() {

            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' ));

            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>

Tuesday, May 16, 2023

Notification to any email address with add to cart woocommerce

 add_action( 'woocommerce_add_to_cart', 'cwpai_woo_send_email_to_admin_on_add_to_cart', 10, 6 );

function cwpai_woo_send_email_to_admin_on_add_to_cart( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) {

  

    $product      = wc_get_product( $product_id );

    $product_name = $product->get_name();

    if ( isset( $_POST['add-to-cart']) ) {

    $company_name =  $_POST['membership_company_name'];

    $contact_person =  $_POST['membership_contact_person'];

    $membership_address =  $_POST['membership_address'];

    $membership_city_town =  $_POST['membership_city_town'];

    $province =  $_POST['province'];

    $postal_code =  $_POST['postal_code'];

    $wcb =  $_POST['wcb'];

    $industry_code_s =  $_POST['industry_code_s'];

    $cor =  $_POST['cor'];

    $expiry_date =  $_POST['expiry_date'];

    $if_your =  $_POST['if_your'];

    }

$data = "<table style='width:50%' cellpadding='5'><tr>

   <th>Item</th>

   <th>Description</th>

   </tr><tr>

   <td>Name</td>

   <td>$product_name</td>

   </tr>

   <tr>

   <td>Company Name:</td>

   <td>$company_name</td>

   </tr>

   <tr>

   <td>Address</td>

   <td>$membership_address</td>

   </tr>

   <tr>

   <td>City/Town</td>

   <td>$membership_city_town</td>

   </tr>

   <tr>

   <td>Province</td>

   <td>$province</td>

   </tr>

   <tr>

   <td>Postal Code</td>

   <td>$postal_code</td>

   </tr>

   <tr>

   <td>WCB #</td>

   <td>$wcb</td>

   </tr>

   <tr>

   <td>Industry Code(s)</td>

   <td>$industry_code_s</td>

   </tr>

   <tr>

   <td>C.O.R #</td>

   <td>$cor</td>

   </tr>

   <tr>

   <td>Expiry Date</td>

    <td>$expiry_date</td>

   </tr>

   <tr>

    <td>If your company has ever registered with another Certifying Partner please name</td>

    <td>$if_your</td>

    </tr></table>";


$headers = array('Content-Type: text/html; charset=UTF-8');

    wp_mail( 'example@gmail.com', 'New notification', $data, $headers );

 

}


For Professional website contact WEB CODE ADDICT

View this post on Instagram A post shared by WebCodeAddict (@webcodeaddicted)