Support » Plugin: WP Menu Cart » Highlight Cart DIV when item added

  • Resolved Jon Dennis

    (@jondennis)


    does anyone know if it is possible to add a simple bit of jquery to this plugin, so that the div containing the menu cart, gets ‘highlighted’ when an item is added to the cart ?

    $('input').change(function(){
    $(this).parent().effect("highlight", {},  5000);
    })

    If so, where would i put this code etc ?

    http://wordpress.org/plugins/wp-menu-cart/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Ewout

    (@pomegranate)

    Hi Jondennis,
    You can put this code in any JS file that is loaded with your theme or the WP Menu Cart plugin, but the safest / most upgrade proof (!) way is probably to output the code into the footer.

    Your example doesn’t work because it’s not using the correct selectors. $('input').change could be any button or text input. You’ll want to use only the add to cart button class. For WooCommerce, that’s .add_to_cart_button, but it depends on your eCommerce system which one you need.
    Then $(this).parent() would be the parent element of the input element. Could be anything. But you want the menu item to highlight, so you’ll have to reference that element. It has a class wpmenucartli that you can use: $(".wpmenucartli").

    Putting everything together:

    add_action('wp_footer', 'wpmenucart_highlight_item');
    function wpmenucart_highlight_item(){
    ?>
    <script type="text/javascript">
    jQuery(document).ready(function($) {
      $(".add_to_cart_button, .edd-add-to-cart, .wpsc_buy_button, .eshopbutton, div.cartopt p label.update input#update").click(function(){
        $(".wpmenucartli").effect("highlight", {},  5000);
      });
    });
    </script>
    <?php
    }

    Now I don’t have jQuery UI installed but it should work (I tested with another function after $(".wpmenucartli").

    Brilliant. Thank you. That worked a charm!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Highlight Cart DIV when item added’ is closed to new replies.