Marketpress: Change category of product when stock gets low

Using PHP in the backend, I'd like to move a product from one category to another if the stock drops to a certain level. Eg. If stock drops to 5, then the product is removed from its usual category and now displays in 'Nearly sold out' category.

I've looked at WP conditionals and the WP update_meta functions but am not sure if I'm on the right track or where the code would be placed.

Anybody have any ideas?


  • Arun Basil Lal

    Hello cowontherun,

    That sounds like a difficult approach. Wouldn't this be easier?

    - List products (say stock under 5) on a page / widget sorted in the increasing order of their stock?

    For this approach, you don't need to change anything, just use a query. We don't have a shortcode for this, but something we could have I suppose:

    [mp_list_products paginate="true" page="1" per_page="10" order_by="stock" order="ASC"]

    Let me ping Paul and see if he can suggest something for you.

  • Paul

    @cowontherun, This is doable but I would advise adding an action when a given product is sold. Via some MarketPress hooks (actions/filters) you can capture when an order is finalized. At this point you can determined the products within the order. For each product you can then query the inventory level. At this point more PHP code to move the product category. Or maybe add to an additional category.

    On the other side of this I would also advise setting up another action to trap when a product is edited. The reason for this is when you increase the inventory. Then you can automatically remove it from the 'Nearly Sold Out' category.

    I'll try and dog some into the MarketPress code to tell you what hooks specifically you need to look at.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.