{"id":486,"date":"2016-02-18T10:42:38","date_gmt":"2016-02-18T10:42:38","guid":{"rendered":"https:\/\/www.sushilkumar.ind.in\/blog\/?p=486"},"modified":"2016-02-18T10:45:57","modified_gmt":"2016-02-18T10:45:57","slug":"how-to-display-product-specific-category-with-woocommerce","status":"publish","type":"post","link":"https:\/\/www.sushilkumar.ind.in\/blog\/woo-commerce\/how-to-display-product-specific-category-with-woocommerce\/","title":{"rendered":"How to Display Product specific category with WooCommerce ?"},"content":{"rendered":"<pre>[tblock tcuscolor=\"#444\" title=\"How to Display Product specific category with WooCommerce ?\" tag=\"h3\"\/]\r\n&lt;?php\r\n\r\n$cate = get_queried_object();\r\n$cateID = $cate-&gt;term_id;\r\n\r\n$args = array(\r\n'hierarchical' =&gt; 1,\r\n'show_option_none' =&gt; '',\r\n'hide_empty' =&gt; 0,\r\n'parent' =&gt; $cateID,\r\n'taxonomy' =&gt; 'product_cat'\r\n);\r\n$subcats = get_categories($args);\r\nforeach ($subcats as $sc) {\r\n$link = get_term_link( $sc-&gt;slug, $sc-&gt;taxonomy );\r\n\r\n?&gt;\r\n\r\n&lt;ul class=\"products\"&gt;\r\n&lt;?php\r\n$args = array( 'post_type' =&gt; 'product','product_cat' =&gt; $sc-&gt;slug, 'posts_per_page' =&gt; 1000,);\r\n$loop = new WP_Query( $args );\r\nif ($loop-&gt;have_posts()) {\r\necho '&lt;h1&gt;&lt;a href=\"'. $link .'\"&gt;'.$sc-&gt;name.'&lt;\/a&gt;&lt;\/h1&gt;';\r\n$i = 1;\r\nwhile ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); global $product; ?&gt;\r\n&lt;?php\r\n\r\nglobal $product, $woocommerce_loop,$wp_query;\r\n\r\n?&gt;\r\n&lt;li class=\"product\"&gt;\r\n\r\n&lt;a href=\"&lt;?php echo get_permalink( $loop-&gt;post-&gt;ID ) ?&gt;\" title=\"&lt;?php echo esc_attr($loop-&gt;post-&gt;post_title ? $loop-&gt;post-&gt;post_title : $loop-&gt;post-&gt;ID); ?&gt;\"&gt;\r\n\r\n&lt;?php woocommerce_show_product_sale_flash( $post, $product ); ?&gt;\r\n\r\n&lt;?php\r\n\r\nif (has_post_thumbnail( $loop-&gt;post-&gt;ID ))\r\necho get_the_post_thumbnail($loop-&gt;post-&gt;ID, 'shop_catalog');\r\nelse\r\necho '&lt;img src=\"'.woocommerce_placeholder_img_src().'\" alt=\"Placeholder\" width=\"300px\" height=\"300px\" \/&gt;';\r\n\r\n?&gt;\r\n\r\n&lt;h3&gt;&lt;?php the_title(); ?&gt;&lt;\/h3&gt;\r\n\r\n&lt;span class=\"price\"&gt;&lt;?php echo $product-&gt;get_price_html(); ?&gt;&lt;\/span&gt;\r\n\r\n&lt;\/a&gt;\r\n\r\n&lt;?php woocommerce_template_loop_add_to_cart( $loop-&gt;post, $product ); ?&gt;\r\n\r\n&lt;\/li&gt;\r\n&lt;?php\r\n\/\/echo $i++;\r\nendwhile;\r\n\r\n?&gt;\r\n\r\n&lt;?php } wp_reset_query(); ?&gt;\r\n\r\n&lt;\/ul&gt;\r\n\r\n&lt;?php } ?&gt;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>[tblock tcuscolor=&#8221;#444&#8243; title=&#8221;How to Display Product specific category with WooCommerce ?&#8221; tag=&#8221;h3&#8243;\/] &lt;?php $cate = get_queried_object(); $cateID = $cate-&gt;term_id; $args = array( &#8216;hierarchical&#8217; =&gt; 1, &#8216;show_option_none&#8217; =&gt; &#8221;, &#8216;hide_empty&#8217; =&gt; 0, &#8216;parent&#8217; =&gt; $cateID, &#8216;taxonomy&#8217; =&gt; &#8216;product_cat&#8217; ); $subcats = get_categories($args); foreach ($subcats as $sc) { $link = get_term_link( $sc-&gt;slug, $sc-&gt;taxonomy ); ?&gt; &lt;ul class=&#8221;products&#8221;&gt; &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[54],"tags":[],"class_list":["post-486","post","type-post","status-publish","format-standard","","category-woo-commerce"],"jetpack_publicize_connections":[],"acf":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p99pkJ-7Q","_links":{"self":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/posts\/486"}],"collection":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/comments?post=486"}],"version-history":[{"count":0,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/posts\/486\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/media?parent=486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/categories?post=486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/tags?post=486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}