Advertisement
lorro

WooCommerce - Show product categories on product page

Apr 30th, 2020
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.47 KB | None | 0 0
  1. <?php
  2.   // WooCommerce - Show product categories on product page
  3.   add_action( 'woocommerce_single_product_summary', 'show_product_categories', 25 );
  4.   function show_product_categories() {
  5.     global $product;
  6.     $terms = get_the_terms( $product->get_id(), 'product_cat' );
  7.     if( $terms ) {
  8.       $names = array();
  9.       foreach ( $terms as $term ) {
  10.         $names[] = $term->name;
  11.       }
  12.       print '<p>Categories: '.join( ', ', $names ).'</p>'.PHP_EOL;;
  13.     }
  14.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement