benkaminski.com


WP E-Commerce Adjust Price Range Widget

WP E-Commerce Adjust Price Range Widget


  benkaminski.com

September 29th, 2013

5 comments Leave A Comment


Here I am again, talking about another issue with WP-Ecommerce… the Price Range Widget. More specifically, the inability to make any adjustments to the ranges specified from the WordPress dashboard. I know WP E-Commerce is free, but do they even offer this ability in their upgraded packages (ability to change price ranges in widget)? Probably not. Which is another story in and of itself, but I’m going to keep this short.

I have seen many people post about this issue across the internet, even on getshopped.org, WP Ecommerce’s official home– but none of the threads have any solid answers. How can I change my price ranges in the Price Range Widget?

My official answer: You still can not adjust them to be exactly a certain range, but you can adjust some of the arguments in the php and get it to be much more accurate, especially for sites selling things UNDER 10 DOLLARS!!! Please, keep reading… I think you’ll like my workaround.

Once again… we have to alter WP E-Commerce CORE code to make this work. Which mean’s it’s another work-around and not an actual solution but this worked so well for me, I was able to get the results I wanted by modifying 2 lines of code. If I knew a bit more about php, I would be able to add a filter to my “functions.php” file in my theme but in the meantime, I think storing this file locally and replacing after update is a small price to pay to have ACCURATE price ranges for your store.

Quickly…

Open

/wp-content/plugins/wp-e-commerce/wpsc-widgets/price_range_widget.php

in your favorite text editor.

Go to line 115 and you will see the following code:


$price_seperater = ceil( $count / 6 );

So, aside from the bad grammar (seperater?) this function performs the math to gather and generate the price ranges and I read in another forum that you can play with this number and get different price ranges. This is true. I started changing the “6” to “5” or “15” or even “-1” just to see what was going on. Basically, this number separates the price ranges by price and the higher number, the more price ranges you get, the lower the number, the less you get. For those that care, “-1” threw an error. Anyhow, this led me to do some more sleuthing…

Edit WPSC Price Range WidgetBy just changing this number we can alter the price ranges, not to an exact number but it’s a start. Although, even in doing this, the lowest price in the range was $10.00. The store that it was applied to had multiple items under $10 that were getting passed over by the price ranges widget. Why was this happening? It just didn’t seem right.

So on a whim, I went a few lines down on the page to line 117 and saw the following code:


$ranges[] = round( $result[$i]['price'], -1 );

Also, on a whim I decided to change the “-1” value to “-0”. Saved the page and refreshed in the browser. Guess what… my products under $10 dollars were now appearing in the price range widget and it made the price ranges much more relative to the products being sold. From there, I revisited the first line of code we discussed. Changed that value to “5” and and was able to find a viable solution for my clients price range needs.

Of course, there are many other factors that will decide whether or not this will work for you. You may have to play with that “$count / 6” divider to get the exact results you’re looking for but after changing the “-1” to “-0”, it’s like the entire widget started making better decisions in its price range calculations. How strange.

Once again, after you modify any core file, you have to save a copy locally until the next plugin update comes out. Then once you update the plugin, re-upload the core file and overwrite the existing one.

If someone want’s to help me come up with a “functions.php” filter for this… I’m all ears. Until then, hope this worked for you and I look forward to your comments.

Leave a Reply

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

This article currently has 5 comments.

A actually great submit by you my friend. We have bookmarked this page and will appear back following several days to examine for any new posts that you simply make.

Hi,
Very good information , I would like change my prices Range as well.But I can’t find /wp-content/plugins/wp-e-commerce/wpsc-widgets/price_range_widget.php. In my website
And tried to find price range in my WPSC default CSS. I have this code but no prices.
Do you know, How I can change it ? or where I can find this information

    @AnnSo
    I’m sorry to disappoint but even on the latest version of WP E-Commerce, the file is still in that location. If you’re not seeing it, perhaps it’s a permissions issue on your server. Either way, I can assure you that the file is located in that folder. Maybe you should re-download the plugin and check the core files from the .zip file?

    Hi – you are correct in that the location is different to that of the post above. The file is now in:
    wpsc-components/theme-engine-v1/widgets

Related Topics: , , , , , , , , , ,