WooCommerce featured products slider automatic cycling

May 2nd, 2012 by Sean Leave a reply »

I have just spent a few hours looking at the dire attempts at making a product slider for WooCommerce. In the end I decided I couldn’t justify even $12 for a premium ‘effort’ on account of it being a bit dire. It seems these days people will cough up for things just because they are paid for on the assumption that because they had to part with some of their hard earned it’s going to be any good. Anyway moving on…

I found the fabulous Wootique theme that is offered as the general purpose theme from WooThemes contains a featured products flipper at the top as an option. It looks great and works with WooCommerce already so why not just make that autocycle? So I did…

Wootique Featured product flipper

The following block of Javascript/jQuery will cause the slider to cycle on every two seconds and when it gets to the end it will reverse direction and start in the opposite direction. Rinse and repeat…

I also added some code to detect when your mouse is hovering over the slider to pause it so it doesn’t carry on sliding whilst you are reading or studying one of the product images.

I shall make the entire thing into a plugin at some point but for now this works beautifully with Wootique or any Woo Theme with the same flipper at the top.

The Code

var hoverpause = 0;

jQuery(document).ready(function () {
    sb_timed_cycle('next');

    jQuery('#featured-products .jcarousel-container').hover(
	function () { hoverpause = 1; },
	function () { hoverpause = 0; }
    );
});

function sb_timed_cycle(direction) {
    setTimeout( function() {
	if (!hoverpause) {
	    if (direction == 'next') {
		if (jQuery('#featured-products .jcarousel-next').attr('disabled') != 'disabled') {
		    jQuery('#featured-products .jcarousel-next').click();
		} else {
		    direction = 'prev';
		    jQuery('#featured-products .jcarousel-prev').click();
		}
	    } else {
		if (jQuery('#featured-products .jcarousel-prev').attr('disabled') != 'disabled') {
		    jQuery('#featured-products .jcarousel-prev').click();
		} else {
		    direction = 'next';
		    jQuery('#featured-products .jcarousel-next').click();
		}
	    }
	}
	sb_timed_cycle(direction);
    }, 2000 );
}

The File
I have written this into a simple, just activate, type plugin for those that prefer this to theme integration. SB Woo Slider Auto Cycle (701 bytes)

17 comments

  1. thomas says:

    dumb question… where do i add this code?

    • Sean says:

      Hi Thomas,

      Not a dumb question at all. If you put it all in a .js file and get your theme to include it in the head section then it will just hook on and work. If you are feeling lazier than that just open up your header.php file and put around it. Should work in that case too.

      cheers
      S

  2. djeko says:

    Hi Sean,

    Thanks for this little script ! It works perfectly for me ;)

    djeko

  3. Bronwyn says:

    Hi Sean, this is a great idea but unfortunately I’m really new to wordpress so I have no idea where to put this code. Are you any closer to making this a plugin for us newbies?

  4. Dan says:

    Hi Sean,

    Great plugin but I’m finding that it’s not pausing the slider when I hover over an item?

    Cheers

    • Sean says:

      Hey Dan. sorry I don’t know why that might be off the top of my head. Does it pause before you add my code? I have been using it for stock Wootique so perhaps it’s not compatible with your theme?

      ta
      S

      • Dan says:

        Thanks for the reply Sean.

        I’m using Woostore so I thought the base structure would be similar to Wootique. I’ve just increased the rotate time to give users a chance to check out the products instead as I’m quite newbie to all this.

  5. kim says:

    Dear Sean..
    Thanks for your plugin. I have install and activated it into my website using Wootique theme, but still featured product image not appear in the flipper below the menu..

    have you any suggestion to make this work?

    • Sean says:

      Hey Kim.. Sorry I don’t understand what you mean. The JS supposed to passively extend the scroller/flipper.. It doesn’t do anything to the images?

      thanks
      Sean

  6. Rocket Robin says:

    Hi Sean,
    This [plugin worked awesomely good for me. Thanks for your valuable contribution. Now, what I need to fix is that when I hover over an item in the slider, there is a flipcard action and on the reverse side of the flipcard, the price states FREE! instead of the price of the item, and for the life of me, I can’t figure out how to edit this… any thoughts… Please go ahead and look at my site if you have time and see what I mean.
    Anyway, thanks very much again for the autocycle, it’s amazingly awesomely good… wait, I already said that, sort of…

  7. Tillie says:

    I would love to be able to control how fast the slider moves and how many seconds it pauses for.

    I found some numbers that I changed which I think controls the pauses, but i want it to slide just a little slower and I don’t know how.

    But either way, I’m appreciative of your work thus far, thank you so much!

    • Sean says:

      Hi Tillie, for that you would need to find the actual jQuery which runs the slider. All this code does it triggers it really.

      ta
      S

  8. Jeremy says:

    Hello, I was curious if there was a way to have it scroll, just one product at a time… and not by “sets”?

    • Sean says:

      Sorry Jeremy this code simply uses JS to press a button which is hidden so the functionality of the original slider can’t be changed. You could add a custom product slider easily enough and you wouldn’t need to use this code I suppose.

      ta
      S

  9. Vinay says:

    Hi,
    Can this work with Mystile theme? It has static featured products? I tried but it didn’t work. How do I change the featured product to autoscroll?

    Thanks

    • Sean says:

      Hi Vinay,

      The slider is different on the Mystile theme. I think you might find a products scroller for WooCommerce on codecanyon or something. That will be by far your best bet for only a few dollars spent.

      Let us know if you find one and rate it for me. I am keen to offer alternative recommendations to my readers..

      thanks
      Sean

Leave a Reply