Support » Plugin: Event Tickets » Unlimited tickets not recognized by function tribe_events_partially_soldout()

  • Resolved Hans Schuijff

    (@hanswitteprins)


    Hi,

    on my website I wanted a call to action to refer to the next available ticket (future event) when a ticket is soldout. To build that I looked in the code to learn how to determine the stock level correctly.

    When trying to differentiate tickets with unlimited stock and limited stock, I found (during testing) that the function tribe_events_partially_soldout() doesn’t recognize unlimited stock correctly. The function looks for (stock === “”) as an indication of unlimited stock, while the stock level of an unlimited ticket seems to be set to -1.

    When I compare to the ticket template file “event-tickets\src\views\blocks\tickets\extra-available.php” and found there it unlimited stock is found by finding the value -1. So that confirms that the -1 value I found as a stock level is deliberate.

    So it seems to me that the code in the function tribe_events_partially_soldout() should also compare to -1 to set the $unlimited_stock indication;

    The line:
    $unlimited_stock = $ticket_stock === '';

    Should then change to something like:
    $unlimited_stock = ( -1 === $ticket_stock );

    As it is tribe_events_partially_soldout() doesn’t not correctly selects unlimited stock tickets so the result is probably incorrect too.

    Regards

    Hans

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Sky Shabatura

    (@skyshab)

    Hi there,

    Thanks for reaching out. I’ll try to help with this if I can.

    Looking this over, this may indeed be a bug. $ticket->stock() will return a -1 if the ticket is unlimited, so I think you are correct about the suggested change.

    This function is “pluggable”, meaning it checks to see if the function already exists before declaring it in our files. This allows you to provide your own version of the function, which will then get used by our plugins anywhere the function is called. It looks like the plugin functions are loaded at the “plugins_loaded” hook. This means you would have to provide your own function before this point. This would need to be declared in a “must use” plugin.

    Can you try copying this function to a must use plugin (in mu-plugins folder) and changing the line that sets the value of $unlimited_stock to -1, and then see if you are seeing the expected result? If so, I can submit a bug ticket.

    It doesn’t look like we are actually using this function in any of our plugins, so it’s not likely anybody would have noticed if it wasn’t working as expected.

    Let me know how that goes!

    Best,
    Sky

    Thread Starter Hans Schuijff

    (@hanswitteprins)

    Hi @skyshab ,

    Thanks for looking into this. I hope tribe will fix the bug at some point too. Until now there seems no hurry to fix that kind of small specific bugs (I brought some earlier), so I tend to make workarounds for myself.

    My plugin uses namespace, so I can also just put the function within the namespace to make it work for me too, when it is just used by my plugin.

    You’re right that I can workaround the problem that way.

    Thanks for the tip.

    Hans.

    Plugin Support Jaime

    (@jaimemarchwinski)

    Hi @hanswitteprins

    Glad to know that workaround resolved your issue for now!

    I’m going to go ahead and close this thread but feel free to open up a new one if anything else comes up.

    Have a wonderful day!

    Thanks,
    Jaime

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Unlimited tickets not recognized by function tribe_events_partially_soldout()’ is closed to new replies.