Home › Forums › Ticket Products › Event Tickets Plus › Custom post meta to show event stock status
- This topic has 5 replies, 2 voices, and was last updated 8 years, 4 months ago by
Christopher.
-
AuthorPosts
-
November 23, 2017 at 4:13 am #1389903
Christopher
ParticipantHi,
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
November 24, 2017 at 8:05 am #1390714Andras
KeymasterHello Christopher,
Thanks for reaching out with your question.
There are 2 functions which might help you make it simpler.
- https://theeventscalendar.com/function/tribe_events_count_available_tickets/
- https://theeventscalendar.com/function/tribe_events_has_soldout/
Try and let me know if that works.
Cheers,
AndrasNovember 27, 2017 at 1:10 am #1392140Christopher
ParticipantHi 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
November 27, 2017 at 3:51 am #1392220Andras
KeymasterHey 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,
AndrasDecember 19, 2017 at 8:35 am #1408783Support Droid
KeymasterHey 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 -
AuthorPosts
- The topic ‘Custom post meta to show event stock status’ is closed to new replies.
