{"id":6378,"date":"2016-02-17T14:18:35","date_gmt":"2016-02-17T19:18:35","guid":{"rendered":"https:\/\/themespress.ca\/?p=6378"},"modified":"2022-09-11T11:23:08","modified_gmt":"2022-09-11T15:23:08","slug":"display-woocommerce-product-categories","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/display-woocommerce-product-categories\/","title":{"rendered":"Display WooCommerce Product Categories"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>With this tutorial, we will show you a way to display your WooCommerce product categories outside of widgets. We will run a query that will display the categories matching the WooCommerce taxonomy.<\/p>\n<p>To find your WordPress taxonomy, simply access your category&#8217;s Post Type and look at the URL.<br \/>\nIn this example, we see this: taxonomy=product_cat in the URL so the taxonomy&#8217;s name is WooCommerce.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n\n\t<div  class=\"wpb_single_image wpb_content_element vc_align_left wpb_content_element\">\n\t\t\n\t\t<figure class=\"wpb_wrapper vc_figure\">\n\t\t\t<div class=\"vc_single_image-wrapper   vc_box_border_grey\"><img decoding=\"async\" width=\"1198\" height=\"564\" src=\"https:\/\/themespress.ca\/wp-content\/uploads\/2017\/02\/wsi-imageoptim-taxonomy.png\" class=\"vc_single_image-img attachment-full\" alt=\"\" title=\"Taxonomy WooCommerce\" srcset=\"https:\/\/themespress.ca\/wp-content\/uploads\/2017\/02\/wsi-imageoptim-taxonomy.png 1198w, https:\/\/themespress.ca\/wp-content\/uploads\/2017\/02\/wsi-imageoptim-taxonomy-600x282.png 600w, https:\/\/themespress.ca\/wp-content\/uploads\/2017\/02\/wsi-imageoptim-taxonomy-300x141.png 300w, https:\/\/themespress.ca\/wp-content\/uploads\/2017\/02\/wsi-imageoptim-taxonomy-1024x482.png 1024w, https:\/\/themespress.ca\/wp-content\/uploads\/2017\/02\/wsi-imageoptim-taxonomy-768x362.png 768w, https:\/\/themespress.ca\/wp-content\/uploads\/2017\/02\/wsi-imageoptim-taxonomy-1320x621.png 1320w\" sizes=\"(max-width: 1198px) 100vw, 1198px\" \/><\/div>\n\t\t<\/figure>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >Display WooCommerce Product Categories<\/h2><div id=\"ts-enlighterjs-container-5656094\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-5656094\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;?php \n$categories = get_categories(&#039;taxonomy=product_cat&amp;amp;hide_empty=1&#039;);\n$select = &quot;&lt;select name=&#039;cat&#039; id=&#039;cat&#039; class=&#039;postform&#039;&gt;\n&lt;option value=&#039;&quot;.$category-&gt;slug.&quot;&#039;&gt;Quelle Occasion ?&lt;\/option&gt;&quot;;\n  foreach($categories as $category){\n  if($category-&amp;gt;count &amp;gt; 0){\n      $select.= &quot;&lt;option value=&#039;&quot;.$category-&gt;slug.&quot;&#039;&gt;&quot;.$category-&gt;name.&quot;&lt;\/option&gt;&quot;;\n  }}\n$select.= &quot;&lt;\/select&gt;&quot;;\necho $select;\n?&gt;<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>With the Javascript, we will specify the desired category and redirect it to the URL matching your category.<\/p>\n<p>After our query, we will add our JavaScript.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-2748203\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-2748203\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"javascript\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;script type=&quot;text\/javascript&quot;&gt;\nvar dropdown = document.getElementById(&quot;cat&quot;);\nfunction onCatChange() {\nif ( dropdown.options[dropdown.selectedIndex].value != -1 ) {\nlocation.href = &quot;&lt;?php echo home_url();?&gt;\/boutique\/categorie\/&quot;+dropdown.options[dropdown.selectedIndex].value+&quot;\/&quot;;\n}}\ndropdown.onchange = onCatChange;\n&lt;\/script&gt;<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>When we look at the redirected ULR in the previous code.<br \/>\nSimply update the URL with the slug category.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-5933312\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-5933312\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">location.href = &quot;&lt;?php echo home_url();?&gt;\/boutique\/categorie\/&quot;+dropdown.options[dropdown.selectedIndex].value+&quot;\/&quot;;<\/pre><\/div><\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"With this tutorial, we will show you a way to display your WooCommerce product categories outside of widgets. We will run a query that will display the categories matching the<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/display-woocommerce-product-categories\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4501,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[357,328],"class_list":["post-6378","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-taxonomy","tag-woocommerce-config"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=6378"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6378\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4501"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}