0

I am trying to determine if any items in a Woocommerce shopping cart are events or not. The tribe_is_event() function doesn't seem to be working as expected, as it always returns false. I'm thinking I'm misunderstanding it's usage.

In the following, I'm looping over all cart items and simply echoing out whether or not it's an event. It always returns "This is normal product", regardless of the type of product it is.

add_action('woocommerce_before_checkout_form', function ($checkout) {
    $items = WC()->cart->get_cart();

    foreach ($items as $item => $values) {
        $post_id = $values['data']->get_id();

        // Why does this not work?
        if(tribe_is_event($post_id)){
            echo 'This is an event!';
        }else{
            echo 'This is normal product';
        }
    }
});

I have logged the $post_id to ensure it's actually the product id I think it is. I've read what I could find online about the function. I feel like it should work in telling me if the product is an event.

Any help would be great :)

Gurnzbot
  • 3,742
  • 7
  • 36
  • 55
  • What do you get if you just run the following line of code with an existing post id? `tribe_is_event( EXISTING POST ID );` You can generally solve these kinds of problems by building your code step by step and each time testing whether the result continues to work, that way you know where it goes wrong – 7uc1f3r Sep 24 '20 at 19:25
  • @7uc1f3r I mentioned in the case, I have logged the `$post_id` to ensure it exists. If I use the function with an event's post id that 100% exists as an event, I get false. If you are asking me to do something else, I apologize! – Gurnzbot Sep 25 '20 at 12:19

0 Answers0