Home Close mini-cart dropdown automatically after 2 seconds in WooCommerce
Reply: 0

Close mini-cart dropdown automatically after 2 seconds in WooCommerce

user3483 Published in April 20, 2018, 10:41 am

In my woocommerce shop, link, I have changed the add to cart button, when a user click on the add to cart button the cart dropdown is droping from to top, how can i close it after 2 seconds unless touched, (flatsome theme) someone can help me figure out what js or other solution i can add to make the cart dropdown close itself after 2 secods?

If someone wants to add a quantity box with +/- next to the add to cart that will show the cart dropdown here is the codes: enjoy.

// JS
function addToCartLink(evt, pid) {
    var x = jQuery("#quantity_" + pid);
    var y = evt.closest("div");
    var qty = y.getElementsByClassName("input-text")[0].value;

 const addToCartUrl = '/?wc-ajax=add_to_cart';
    var xWWWFormUrlencodedData = "quantity=" + qty;
xWWWFormUrlencodedData += "&product_id=" + pid;
 jQuery.post(addToCartUrl, xWWWFormUrlencodedData, {
        withCredentials: true,
        headers: {
            'Cache-Control': 'no-cache',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'Pragma': 'no-cache'
    }).success(result => {
        if (result.error) {
            console.warn('The product has been added to the cart despite that the result object indicates an error!');
        console.log('Success.', result);
        jQuery(".header .cart-icon").replaceWith(result.fragments[".header .cart-icon"]);


 return false;


and in functions.php

add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) {
    if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() && ! is_cart() ) {

        $html = '<a rel="nofollow" data-product_id="'. $product->id .'" onclick="addToCartLink(this,' . $product->id .')" class="add_to_cart_button product_type_simple button primary is-flat mb-0 is-small">הוסף לסל</a>';
        //$html = '<a onclick="addToCartLink(this,'. $product->id .')">הוסף לסל</a>';

        $html .= '<div class="quantity buttons_added">';
        $html .= '<input type="button"  value="-"  class="minus button is-form">';
        $html .= '<input type="number" id="quantity_'. $product->id .'" class="input-text qty text" step="1" min="0" max="9999" name="quantity" value="1" title="כמות" size="4" pattern="[0-9]*" inputmode="numeric" >';
        $html .= '<input type="button" value="+" class="plus button is-form">';
        $html .= '</div>';

    return $html;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.385453 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO