{"id":29505,"date":"2023-01-24T18:08:03","date_gmt":"2023-01-24T17:08:03","guid":{"rendered":"http:\/\/alessandrobuzzi.com\/?p=29505"},"modified":"2023-01-24T18:08:03","modified_gmt":"2023-01-24T17:08:03","slug":"woocommerce-add-text-to-product-price","status":"publish","type":"post","link":"https:\/\/alessandrobuzzi.com\/?p=29505","title":{"rendered":"Woocommerce add text to product price"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">To add a text after the product price for a single product on WooCommerce, you can use the following code snippet:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">add_filter( 'woocommerce_get_price_html', 'custom_price_message', 100, 2 );\nfunction custom_price_message( $price, $product ){\n    if( is_product() &amp;&amp; $product->get_id() === YOUR_PRODUCT_ID ) {\n        $price .= '&lt;p>Your custom message here&lt;\/p>';\n    }\n    return $price;\n}\n\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You need to replace YOUR_PRODUCT_ID with the ID of the specific product you want the custom message to appear for. You can get the product ID by going to the product&#8217;s Edit page on the WordPress dashboard, it&#8217;s listed on the top right corner.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also use the same approach to target multiple products by adding an array of IDs and using the <code>in_array()<\/code> function to check if the current product&#8217;s ID is in the array of IDs you want to target.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">add_filter( 'woocommerce_get_price_html', 'custom_price_message', 100, 2 );\nfunction custom_price_message( $price, $product ){\n    $product_ids = array( YOUR_PRODUCT_ID1, YOUR_PRODUCT_ID2);\n    if( is_product() &amp;&amp; in_array( $product->get_id(), $product_ids ) ) {\n        $price .= '&lt;p>Your custom message here&lt;\/p>';\n    }\n    return $price;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Please note that the above code snippet is an example and you should test it in your environment to ensure it works as expected.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To add a text after the product price for a single product on WooCommerce, you can use the following code snippet: You need to replace YOUR_PRODUCT_ID with the ID of the specific product you want the custom message to appear for. You can get the product ID by going to the product&#8217;s Edit page on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":29512,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11,14],"tags":[22,21],"class_list":["post-29505","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tech","category-wordpress","tag-price","tag-woocommerce"],"acf":[],"_links":{"self":[{"href":"https:\/\/alessandrobuzzi.com\/index.php?rest_route=\/wp\/v2\/posts\/29505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alessandrobuzzi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alessandrobuzzi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alessandrobuzzi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alessandrobuzzi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=29505"}],"version-history":[{"count":0,"href":"https:\/\/alessandrobuzzi.com\/index.php?rest_route=\/wp\/v2\/posts\/29505\/revisions"}],"wp:attachment":[{"href":"https:\/\/alessandrobuzzi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=29505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alessandrobuzzi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=29505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alessandrobuzzi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=29505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}