RSS Feed

WordPress eCommerce – popular products IMPROVED

November 20, 2011 by Dave

My previous post on how to get popular products from WP eCommerce is a little dated and doesn’t actually work too well. (in fact my client updated after being specifically told not to update wp ecommerce. Poor I know but what’r'ya gonna do?)

SO I’ve re-written most of the code and now it can be updated and has all the correct details and should work with variations. See the code below:


28 Comments »

  1. mroncetwice says:

    YES!

    Literally within the last hour found the related thread in the GetShopped forums and read through and attempted implementing, without success, ChainsawDR’s latest function based on your explorations. So, after snooping around your blog here a bit, I see you’ve been up to even more meddling! And just in time for the holidays!

    Thank you (and ChainsawDR) so much for keeping us all informed on your discoveries and developments.

    BD

    • Dave says:

      Hey buddy, no worries! Where would developers be without sharing the knowledge? I still find it shocking this isn’t a standard feature!

    • mroncetwice says:

      hey again!

      Just want to let you know of a problem I came across while using your script and the (hopefully legit) solution that I whipped up-

      So, I’m using your script for an apparel sales site where there are a bunch of size variations.. Well, the problem I found is that the permalink to each of the popular products output by your awesomely helpful script was somehow incorrect. It turns out that the permalink is pointing to that of the individual variation (which is a set of posts numbered successively after the product post which is the parent of these sub-posts) rather than to the actual product (which is actually the parent of the variation posts). So, the permalink was going to an uncategorized, ghost product page instead of the actual product page.

      Solution: set $post as global, then set $post as your $product value (get_post($item['prodid'])) … Then, inside the get_permalink() call, I specified the ID via $post->post_parent, which returns the correct (parent) product permalink URL.

      P.S. Though I’ve not used it much, I have been following the Instinct crew on the developments of the WP-e-Commerce plugin since early 2009 and am not surprised one bit at the lack of such a useful feature, nor the lack of documentation on the scripts used to get such a feature going.

      Thank again for the awesome work you’ve done here.

      • Dave says:

        You sir are a legend, i woke up this morning and found this exact bug recorded in my bug tracker. Very well done!

        I’ve been using it for a couple years now too and its come a long way but still lacks some basic functionality such as this; which is why i post these things :) again, good job man, i will update the post with the new code later on today.

  2. Rodolfo says:

    yep. Thanks you guys. i’ve managed to implement it custom based.
    ps- you don’t actually need to custom the price funcion, you can do:

  3. Rodolfo says:

    echo wpsc_currency_display(get_post_meta( $item['prodid'], ‘_wpsc_price’, true ));

  4. Dave says:

    Hey guys,

    I’ve updated the code to work with the latest version of WP eCommerce. You should all receive this by email :) Enjoy!

  5. Brandon says:

    Awesome, i will most likely be using this for my next project. Much appreciated Dave!

  6. emerson says:

    Another nice and a brilliant work Sir Dave. Thanks for this post.

  7. emerson says:

    Good day sir!

    Can i also have the final code for the popular product function. Please send it to my email account. I’m just trying the codes posted here, but no luck.

    thanks,
    emerson

  8. Anthony says:

    Thanks Dave, great stuff!

  9. Joel says:

    Great post, but I’m having trouble turning this into a widget. Links show up in the widget but they’re blog posts, not products. Any idea where I could have went wrong?

  10. andrew says:

    you should put all your html into a variable and return it instead of echo/print so you can use the shortcode in page/post content and not mess with anything

  11. jawad says:

    Hi

    i am not sure but i just noticed a problem. i converted your code so that i can use it with shortcode kind of putting it on a page. now it works fine but what i noticed is that when ever i use it after that i can only call one category using shortcode which is [wpsc_products category_id='4']

    so if i use it more than once. i can only get the first category.

    thank you

    jawad

    • Dave says:

      You converted the code? converted it to what?

      • jawad says:

        Hi

        well I bascially make the output in a variable since I am using it as a short code so only echo is replaced by $output_html and then I return it in the function end.

        But i figure out the problem upto some extent if you can confirm that it would be great as i am just a beginner in wp i mostly work in joomla and simple php.

        1) i have added the global $post; in the top along with the wpdb object

        then in the loop instead of $item in foreach I used $post and replace $item with $post every where then in the loop I add this code

        setup_postdata($post);

        and now it seems to be working with the wp ecommerece category short code as well.

        hopefully that may fix another case which i just find out.

        thank you

        jawad

  12. vipin pandey says:

    Hi,
    i am using wp-e-commerce plugin into my website. On products-page using dropdown i want to filter products by price(low to high and vice versa) and rating(high to low and vice versa).

    thank you
    vipin pandey

  13. coggia says:

    Hi,
    I don’t know why this short code doesn’t display anything.
    It’s working but doesn’t display a thing. Maybe because in my wp e-commerce site I cannot let the user to buy things but to go on an external site to buy them?..

    Is there a way to get the most Popular VIEWED products instead of buyed ones?

  14. Coggia says:

    Hello,
    i’m curious, your current code is for what you call “most popular products”,
    but it search in the cart content, right? so it’s the most bought products.
    What if I want to see the most VIEWED products? where should i look instead of the wpsc_cart_contents?
    it would be nice to you if you could get me a lead :)

    • Dave says:

      There isn’t really any easy way to do it, the only available information from stock is what people add to their cart. I would suggest looking for a plugin to do what you want rather than building it yourself. I’m sure a plugin exists for it.

      • Tha PHLASH says:

        Word up Dave… i was wondering if you could help me out? Im using this script for my bestseller page… but its also pulling the ‘zero priced’ products and could really use a hand… feel like i tried everything…

        • Dave says:

          Have you started a Stack Overflow thread or have a pastebin of your code anywhere?

          My only suggestion would be to get the price before outputting any of the html and check that it isn’t zero before outputting.

      • Coggia says:

        ok thanks anyway;
        i’ll continue my search :)

        • Dave says:

          Okay, good luck. I wouldn’t have said it was a popular product unless someone has bought it anyway so you might be looking for something more like a most viewed. Still, the same issue though. I would have a custom table with that information in it and link the products via their product ID to it to order by when fetching them.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>