Custom post meta to show event stock status

Home Forums Ticket Products Event Tickets Plus Custom post meta to show event stock status

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1389903
    Christopher
    Participant

    Hi,

    I have a page on a clients website which uses WP Advanced search to display all the events and allow users to filter, search and order the events. Generally this works well with the filters working as intended.

    The client then requested an additional filter to filter by events that are in stock and out of stock. To filter the events I have to use the post meta attached to the event rather than the product linked to the event. I have looked and the instock meta is attached to the product which has caused a few issues.

    To get around this problem, I wrote a custom function which fires when an order is placed for an event via a WooCommerce hook. The function finds the product ID, gets the stock status of the product and its parent id before adding a custom meta field to the event showing whether it is in stock or out of stock. In theory this process works and does work, but is quite temperamental and doesn’t always add the custom post meta of ‘In Stock’ or ‘Out of Stock’ correctly to the relevant event.

    Can you suggest a better, and possibly simpler way to achieve this? All I want is for each of the events to have a custom meta field which shows whether the event is in stock or out of stock. If I have this, the filtering system I have will work perfectly.

    Many Thanks

    #1390714
    Andras
    Keymaster

    Hello Christopher,

    Thanks for reaching out with your question.

    There are 2 functions which might help you make it simpler.

    Try and let me know if that works.

    Cheers,
    Andras

    #1392140
    Christopher
    Participant

    Hi Andras,

    Thanks for your response.

    Both those functions are very useful and I can use them both to check if the event is in stock. However, with the way the search is built, I need to query by meta key, meaning I will need to store custom meta on the event to show whether or not the event is in stock

    Ideally, I would have a meta key called something like _is_instock and I could use the tribe_events_has_soldout function to populate the meta value of this as true or leave blank.

    I think I need a hook which will run a function at the appropriate time and make sure this meta value is always up to date and correct.

    Do you have any suggestions?

    Thanks

    #1392220
    Andras
    Keymaster

    Hey Christopher,

    There should be a hook when completing a WooCommerce purchase. I would use that to use one of the above functions to check the “sold out” status and then save the meta.

    You can find a list of WooCommerce hooks and filters here.

    Also this article references some hooks related to orders, but not sure how up-to-date that is.

    Cheers,
    Andras

    #1408783
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Custom post meta to show event stock status’ is closed to new replies.