Hype Matrix
Hype Matrix

Reputation: 19

Woocommerce how to use ternary operator to display featured products

I have added the following code to display "Featured: yes/no":

<div class="event-package-content">
    Featured: <?php echo $product->get_event_listing_featured(); ?>
</div>

I would like to change it to display only the word "Featured" under the package if the package is featured instead of "yes/no".

Package screenshot:

Package screenshot

Packages (shows after filling in details)

Can anyone please help?

Thanks.

Upvotes: 1

Views: 45

Answers (1)

Ruvee
Ruvee

Reputation: 9097

You could replace your code:

<div class="event-package-content">
    Featured: <?php echo $product->get_event_listing_featured(); ?>
</div>

With this:

<div class="event-package-content">
  <?php echo ($product->get_event_listing_featured() == "yes") ? "Featured": ""; ?>
</div>

Upvotes: 2

Related Questions