Tutorial: Pricing Based on Inventory

FoxyShop was developed to be extremely flexible so that developers could do anything they needed to with the product structure. Recently I had someone come to me looking to charge different amounts based on the inventory level. It was an interesting challenge and I want to share it with you the results as a guide for your own “extreme” customizations.

Take a look at the source code.

This particular product needed to charge $5 if there were 100 tickets available, $10 if there were under 90, $20 if there under 60, and $25 for the last 20 tickets. I put the source code from the link above in my functions.php file and then setup the new Price Levels field with the syntax as you see in the image at right. This new field is added by the custom code – you can add any fields you want with this hook.

The specialized code uses hooks to tie into the core FoxyShop functionality. In this case, we’re checking for the new custom field and if it is set, we’re looking at the current inventory and adjusting the price. This happens deep within the FoxyShop process so it will be applied anywhere FoxyShop grabs the price. It also ignores this functionality if the customized price field isn’t set. Of course, you’ll have to set the inventory for this particular product code.

While you may not need this exact feature, this guide can serve as a helpful starting point for your own customization with examples of how to tie into FoxyShop’s core. As always, if you need a hook or filter added to the core for some functionality I haven’t yet thought of, please let me know. I’m here to help!

2 Responses to Tutorial: Pricing Based on Inventory

Leave a Reply

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