title: Display Woocommerce product attributes in a custom single post
body: <p>i have an custom single post and show the product price and product tags and content , now i need show the product attribute in below of content but i test the many code , i can't show in my single post .
  i need a code for <code>echo</code>the product attribute in single post .</p>
  
  <p>this is my <strong>single.php</strong></p>
  
  <pre><code>        &lt;?php get_header(); ?&gt;
      &lt;div itemscope itemtype="http://schema.org/Product" id="single"&gt;
      &lt;div id="similar"&gt;
      &lt;h2&gt;&lt;i class="icon-film"&gt;&lt;/i&gt;similar product&lt;/h2&gt;
      &lt;?php
      $related = get_posts( array( 'category__in' =&gt; wp_get_post_categories($post-&gt;ID), 'post_type' =&gt; 'product' , 'orderby' =&gt; 'rand' , 'numberposts' =&gt; 8, 'post__not_in' =&gt; array($post-&gt;ID) ) );
      if( $related ) foreach( $related as $post ) {
      setup_postdata($post); ?&gt;
      &lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php the_title(); ?&gt;"&gt;&lt;?php if ( has_post_thumbnail() ) {the_post_thumbnail('first-thumb');} else { ?&gt;&lt;/a&gt;
      &lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php the_title(); ?&gt;"&gt;
      &lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;/assets/img/no-image.png" alt="&lt;?php the_title(); ?&gt;" /&gt;&lt;?php } ?&gt;&lt;/a&gt;
      &lt;?php }
      wp_reset_postdata(); ?&gt;
  
      &lt;ul class="product_tags"&gt;
      &lt;h3&gt;&lt;i class=" icon-uniE887"&gt;&lt;/i&gt;product tag&lt;/h3&gt;
      &lt;?php woocommerce_product_loop_tags() ?&gt; 
      &lt;/ul&gt;
  
      &lt;/div&gt;
      &lt;div id="single_body"&gt;
      &lt;?php if (have_posts()) : ?&gt;
      &lt;?php while (have_posts()) : the_post(); ?&gt;
  
  
  
  
      &lt;div class="h1"&gt;&lt;i class="icon-quill"&gt;&lt;/i&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" title="&lt;?php the_title(); ?&gt;"&gt;
      &lt;h1&gt;&lt;span itemprop="name"&gt;
      &lt;?php the_title(); ?&gt;
      &lt;/span&gt;&lt;/h1&gt;
      &lt;/a&gt;
      &lt;ul class="title_icon"&gt;
      &lt;li title="view"&gt;&lt;i class="icon-uniE850"&gt;&lt;/i&gt;&lt;?php if(function_exists('the_views')) { the_views(); } ?&gt;&lt;/li&gt;
      &lt;li title="comment"&gt;&lt;i class="icon-bubbles2"&gt;&lt;/i&gt;&lt;?php comments_popup_link('0 ','1 ', '% '); ?&gt;&lt;/li&gt;
      &lt;li title="date"&gt;&lt;i class="icon-clock"&gt;&lt;/i&gt;&lt;?php the_time('Y/m/d') ?&gt;&lt;/li&gt;
      &lt;/ul&gt;
      &lt;/div&gt;
      &lt;p&gt;&lt;?php the_content()?&gt;&lt;/p&gt;
      &lt;?php endwhile;endif; ?&gt;
      &lt;/div&gt;
  
      &lt;ul class="product_etc"&gt;
      &lt;h3&gt;&lt;i class="icon-uniE02A"&gt;&lt;/i&gt;detail of productل&lt;/h3&gt;
      &lt;li itemprop="offers" itemscope itemtype="http://schema.org/Offer"&gt;&lt;strong&gt;price&lt;/strong&gt;
      &lt;div class="price" itemprop="price" &gt;&lt;?php echo $product-&gt;get_price_html(); ?&gt;&lt;/div&gt;&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;category&lt;/strong&gt;&lt;span&gt;&lt;?php echo $product-&gt;get_categories( ', ', '' . _n( '', '', sizeof( get_the_terms( $post-&gt;ID, '' ) ), '' ) . ' ', '' ); ?&gt;&lt;/span&gt;&lt;/li&gt;
      &lt;?php woocommerce_template_loop_add_to_cart( $loop-&gt;post, $product ); ?&gt;
  
      &lt;/ul&gt;
  
      &lt;div class="clear"&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="clear"&gt;&lt;/div&gt;
      &lt;div class="comments-page"&gt;&lt;?php comments_template(); ?&gt;&lt;/div&gt;
  
      &lt;?php wp_reset_query(); ?&gt;
      &lt;?php get_footer(); ?&gt;
  </code></pre>
  
  <p>and this is my <strong>function.php</strong></p>
  
  <pre><code>                            &lt;?php
      add_filter('show_admin_bar','__return_false');
      function the_content_limit($max_char, $stripteaser = 0, $more_file = '') {
      $content = get_the_content($more_link_text, $stripteaser, $more_file);
      $content = apply_filters('the_content', $content);
      $content = str_replace(']]&gt;', ']]&amp;gt;', $content);
      $content = strip_tags($content,'');
  
      if (strlen($_GET['p']) &gt; 0) {
      echo "&lt;p&gt;";
      echo $content;
      echo "&lt;/p&gt;";
      }
      else if ((strlen($content)&gt;$max_char) &amp;&amp; ($espacio = strpos($content, " ", $max_char ))) {
      $content = mb_substr($content, 0, $espacio);
      $content = $content;
      echo "&lt;p&gt;";
      echo $content;
      echo "...";
      echo "&lt;/p&gt;";
      }
      else {
      echo "&lt;p&gt;";
      echo $content;
      echo "&lt;/p&gt;";
      }
      }
      //thumbnails
      if (function_exists('add_theme_support')) {
  
      add_theme_support('post-thumbnails');
      }
      //comments
      if ( $_GET['post_type'] != 'page' ) {add_post_meta($post_id, 'series', '', true);}
      function mytheme_comment($comment, $args, $depth) {
      $GLOBALS['comment'] = $comment;
      extract($args, EXTR_SKIP);
  
      if ( 'div' == $args['style'] ) {
      $tag = 'div';
      $add_below = 'comment';
      } else {
      $tag = 'li';
      $add_below = 'div-comment';
      }
      ?&gt;
      &lt;&lt;?php echo $tag ?&gt; &lt;?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?&gt; id="comment-&lt;?php comment_ID() ?&gt;"&gt;
      &lt;?php if ( 'div' != $args['style'] ) : ?&gt;
      &lt;div class="reply"&gt;
      &lt;?php comment_reply_link( array_merge( $args, array( 'add_below' =&gt; $add_below, 'depth' =&gt; $depth, 'max_depth' =&gt; $args['max_depth'] ) ) ); ?&gt;
      &lt;/div&gt;
      &lt;div id="div-comment-&lt;?php comment_ID() ?&gt;" class="comment-body"&gt;
      &lt;?php endif; ?&gt;
      &lt;div id="comments_data"&gt;
      &lt;?php printf( __( '&lt;span class=""&gt;نظر&lt;/span&gt; &lt;cite class="fn"&gt;%s&lt;/cite&gt;' ), get_comment_author_link() ); ?&gt;
      &lt;?php if ( $comment-&gt;comment_approved == '0' ) : ?&gt;
      &lt;em class="comment-awaiting-moderation"&gt;&lt;?php _e( 'Your comment is awaiting moderation.' ); ?&gt;&lt;/em&gt;
      &lt;br /&gt;
      &lt;?php endif; ?&gt;
  
      &lt;div class="comment-meta commentmetadata"&gt;&lt;a href="&lt;?php echo htmlspecialchars( get_comment_link( $comment-&gt;comment_ID ) ); ?&gt;"&gt;
      &lt;?php
      /* translators: 1: date, 2: time */
      printf( __('&lt;span class=""&gt;در تاریخ: &lt;/span&gt;&lt;br/&gt; %1$s'), get_comment_date(),  get_comment_time() ); ?&gt;&lt;/a&gt;&lt;?php edit_comment_link( __( '(Edit)' ), '  ', '' );
      ?&gt;
      &lt;/div&gt;
      &lt;/div&gt;
      &lt;?php comment_text(); ?&gt;
  
  
      &lt;!---&lt;div class="comment-author vcard"&gt;
      &lt;?php if ( $args['avatar_size'] != 0 ) echo get_avatar( $comment, $args['avatar_size'] ); ?&gt;
  
      &lt;/div&gt;---&gt;
      &lt;?php if ( 'div' != $args['style'] ) : ?&gt;
      &lt;/div&gt;
      &lt;?php endif; ?&gt;
      &lt;?php
      }
      //woocommerce
      add_action( 'after_setup_theme', 'woocommerce_support' );
      function woocommerce_support() {
      add_theme_support( 'woocommerce' );
      }
  
      // Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php)
      add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' );
      function woocommerce_header_add_to_cart_fragment( $fragments ) {
      ob_start();
      ?&gt;
      &lt;a class="cart-contents" href="&lt;?php echo WC()-&gt;cart-&gt;get_cart_url(); ?&gt;"&gt;&lt;?php echo sprintf (_n( '%d محصول', '%d محصول', WC()-&gt;cart-&gt;get_cart_contents_count() ), WC()-&gt;cart-&gt;get_cart_contents_count() ); ?&gt; به ارزش &lt;?php echo WC()-&gt;cart-&gt;get_cart_total(); ?&gt;&lt;/a&gt;
      &lt;?php
  
      $fragments['a.cart-contents'] = ob_get_clean();
  
      return $fragments;
      }
  
      add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_product_loop_tags', 5 );
      function woocommerce_product_loop_tags() {
      global $post, $product;
      $tag_count = sizeof( get_the_terms( $post-&gt;ID, 'product_tag' ) );
      echo $product-&gt;get_tags( ', ', '&lt;span class="tagged_as"&gt;' . _n( '', '', $tag_count, 'woocommerce' ) . ' ', '.&lt;/span&gt;' );
      }
  
      add_action( 'woocommerce_single_product_summary', 'product_attribute_after_price', 15 );
      function product_attribute_after_price () {
      global $product;
  
      // HERE add your product attribute SLUG or taxonomy
      $attribute_slug = 'color';
  
      $taxonomy = strpos($url, 'blog') !== false ? $attribute_slug : 'pa_' . $attribute_slug;
      $attribute_name = get_taxonomy( $taxonomy )-&gt;labels-&gt;singular_name;
      $term_name = $product-&gt;get_attribute( $taxonomy ); // The value
  
      if( empty($term_name) ) return; // Exit if empty value
  
      // If not empty we display it
      $output  = '&lt;div class="product-attribute '.$taxonomy.'"&gt;&lt;p&gt;';
      $output .= '&lt;strong&gt; '.$attribute_name.'&lt;/strong&gt;: ';
      $output .= '&lt;span&gt; '.$term_name.'&lt;/span&gt;';
      echo $output . '&lt;/p&gt;&lt;/div&gt;';
      }
  
      ?&gt;
  </code></pre>