samedi 15 juillet 2017

WooCommerce - button on product page visible only for certain categories

I have added a custom button to product page that is connected to product meta demo_url, which is just an URL that changes by each product (to open live demo for each product separately in a lightbox). The code is quite simple:

function my_extra_button_on_product_page() {
  global $product;
  $demo_url = get_post_meta( get_the_ID(), 'demo_url', true );
  echo '<a class="fancybox iframe" data-width="1280" data-height="720" href="'.$demo_url.'"><button style="background: lightblue; padding-left: 19px; padding-right: 19px;">Przymierz</button></a>';
}

The thing is, there are some other products in the shop that do not use live demo function. They are listed in different categories. I would like this button to be visible ONLY for certain product category (or invisible for two product categories - whatever is easier).

I suppose this should be done via get_cat_ID( $cat_name ), but I am unsure how to write the if function and generally I'm not really code-savvy.

If anyone could be kind enough to show me how this works, I'll gladly take the lesson :)

Thank You in advance, Tomasz

Aucun commentaire:

Enregistrer un commentaire