{"id":6259,"date":"2016-10-15T12:50:55","date_gmt":"2016-10-15T16:50:55","guid":{"rendered":"https:\/\/themespress.ca\/?p=6259"},"modified":"2022-09-06T19:37:48","modified_gmt":"2022-09-06T23:37:48","slug":"display-woocommerce-products","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/display-woocommerce-products\/","title":{"rendered":"Display WooCommerce Products"},"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>This tutorial will show you how to display your featured WooCommerce products with a query.<\/p>\n<p>It is a simply query, however however our arguments we need to fetch the WooCommerce <strong>product<\/strong> post type. The <strong>&#8216;meta_key&#8217; &#038;=> &#8216;_featured&#8217;<\/strong> will return featured products. We will also have the WooCommerce pagination hook.<\/p>\n<p>With our first argument, we will create a variable that will store the product ID:<br \/>\n$id = $product->id;. This will allow use to fetch the product ID within the add_to_cart WooCommerce shortcode:<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-3199410\" 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-3199410\" 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 echo do_shortcode(&#039;[add_to_cart id=&quot;&#039;.$id.&#039;&quot;]&#039;); ?&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>You can stylized your products as you see fit via the CSS files.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >Display WooCommerce Products<\/h2><div id=\"ts-enlighterjs-container-3218595\" 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-3218595\" 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;div class=&quot;woocommerce columns-3&quot;&gt;\n\t&lt;ul class=&quot;products&quot;&gt;\n\t\t&lt;?php \n\t\t$id = $product-&gt;id; \n\t\t$args = array( \n\t\t&#039;post_type&#039;           =&gt; &#039;product&#039;, \n\t\t&#039;meta_key&#039;            =&gt; &#039;_featured&#039;,\n\t\t&#039;posts_per_page&#039;      =&gt; 3, \n\t\t&#039;columns&#039;             =&gt; &#039;3&#039;, \n\t\t&#039;meta_value&#039;          =&gt; &#039;yes&#039; \n\t\t); \n\n\t\t$loop = new WP_Query( $args ); while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); \n\t\tglobal $product; \n\t\t?&gt;\n\t\t&lt;li class=&quot;product&quot;&gt;&lt;\/li&gt;\n\t\t&lt;?php endwhile; ?&gt;\n\t\t&lt;?php wp_reset_postdata(); ?&gt;\n\t&lt;\/ul&gt;\n&lt;\/div&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>You can implement it in any template you want.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"This tutorial will show you how to display your featured WooCommerce products with a query. It is a simply query, however however our arguments we need to fetch the WooCommerce<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/display-woocommerce-products\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4546,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[328],"class_list":["post-6259","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-woocommerce-config"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6259","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=6259"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6259\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4546"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6259"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}