{"id":6174,"date":"2017-05-05T14:26:17","date_gmt":"2017-05-05T18:26:17","guid":{"rendered":"https:\/\/themespress.ca\/?p=6174"},"modified":"2022-09-01T19:12:14","modified_gmt":"2022-09-01T23:12:14","slug":"woocommerce-price-free-price","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/woocommerce-price-free-price\/","title":{"rendered":"WooCommerce Price: How to set Free as a Price"},"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><strong>Woocommerce Price:<\/strong> Here&#8217;s a short tutorial on how to display free as a price once an item&#8217;s price is set at 0$.<\/p>\n<p>We will use the <a href=\"http:\/\/hookr.io\/filters\/woocommerce_get_price_html\/\" target=\"_blank\" rel=\"noopener\">woocommerce_get_price_html<\/a> filter which will verify if an item&#8217;s price is 0$ or empty and then return the text with the $price variable.<\/p>\n<p>Add this filter in your functions.php file.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-9166427\" 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-9166427\" 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=\"\">\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ Get Free if the price Woocommerce = 0\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\nadd_filter( &#039;woocommerce_get_price_html&#039;, &#039;themepress_price_html&#039;, 10, 2 );\nfunction themepress_price_html( $price, $product ) {\n  if( $product-&gt;get_price() == 0 ||  $product-&gt;get_price() == &#039;&#039;) {\n  $price = &#039;&lt;span class=&quot;woocommerce-Price-amount amount&quot;&gt;Gratuit&lt;\/span&gt;&#039;;\n  }\nreturn $price;\n}<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>Once the condition is configured, you can display the text you want insde the woocommerce-Price-amount span tag.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"Woocommerce Price: Here's a short tutorial on how to display free as a price once an item's price is set at 0$. We will use the woocommerce_get_price_html filter which will<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/woocommerce-price-free-price\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4644,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[328],"class_list":["post-6174","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\/6174","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=6174"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6174\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4644"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}