WooCommerce: Display Content Above Add to Cart @ Single Product Page

A client of mine decided to add a little notice (“30-day return policy offered”) just above the Add to Cart button on the WooCommerce single product page. There is no need to say this will allow her to increase the click-through rate and her sales conversion rate.

So, how to do this? Once again, it’s very simple. Just copy/paste the following snippet in your functions.php template file:

The PHP snippet to show text above Add to Cart:


/**
 * @snippet       Adds notice at single product page above add to cart
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=349
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.4.5
 */

add_action( 'woocommerce_single_product_summary', 'bbloomer_show_return_policy', 20 );

function bbloomer_show_return_policy() {
    echo '<p class="rtrn">30-day return policy offered. See Terms and Conditions for details.</p>';
}

The CSS customization

As you may have noticed, the HTML paragraph tag has an “id” so that you can style it via CSS. In my example I wrote this in the custom.css file:


.rtrn {
text-align: center;
font-style: italic;
}

Here’s the WooCommerce snippet final result:

WooCommerce: add notice @ single product page
WooCommerce: add notice @ single product page

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce Visual Hook Guide: Single Product Page
    Here’s a visual hook guide for the WooCommerce Single Product Page. This is part of my “Visual Hook Guide Series“, through which you can find WooCommerce hooks quickly and easily by seeing their actual locations (and you can copy/paste). If you like this guide and it’s helpful to you, let me know in the comments! […]
  • WooCommerce: Disable Variable Product Price Range $$$-$$$
    You may want to disable the WooCommerce variable product price range which usually looks like $100-$999 when variations have different prices (min $100 and max $999 in this case). With this snippet you will be able to hide the highest price, and add a “From: ” prefix in front of the minimum price. At the […]
  • WooCommerce: Hide Price & Add to Cart for Logged Out Users
    You may want to force users to login in order to see prices and add products to cart. That means you must hide add to cart buttons and prices on the Shop and Single Product pages when a user is logged out. All you need is pasting the following code in your functions.php (please note: […]
  • WooCommerce: Add Custom Field to Product Variations
    Adding and displaying custom fields on WooCommerce products is quite simple. For example, you can add a “RRP/MSRP” field to a product, or maybe use ACF and display its value on the single product page. Easy, yes. Unfortunately, the above only applies to “simple” products without variations (or the parent product if it’s a variable […]
  • WooCommerce: Show Number Of Products Sold @ Product Page
    WooCommerce database already stores the number of products sold for you. Therefore, you may want to show such number on the product page, close to the Add To Cart button. As we’ve seen in my book Ecommerce and Beyond, showing the number of sales for each product can increase your sales conversion rate. All you […]

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

94 thoughts on “WooCommerce: Display Content Above Add to Cart @ Single Product Page

  1. What if I only want the text to show on items with a chosen tag?

  2. Hi,
    Thanks for this useful content.
    How can i customize to showing that text only for some products not at all single pages?
    (For example, do not show in β€œout of stock” products.)
    Can you explain about it?
    Thank you
    With Best Regards

    1. Hello Sam, I suggest you take a look at “conditional logic”: https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Enjoy πŸ™‚

      1. Thank You

        1. You are awesome and your website is exceptional

  3. Hi! I tried adding this and it did not work. I got the error message on product page “Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘return_policy’ not found or invalid function name in /home/hearta06/public_html/wp-includes/class-wp-hook.php on line 286″. ”

    Even after deleting the code, the message still appears.

    Can you advise how to get rid of this?

    1. Hello Melissa – thanks so much for your comment! Just make sure the “add_action” and the “function” use the same function name πŸ™‚

      1. Hello Rodolfo, I hope you are well!

        How could I do to show this message in the single product page for every product, and also add it below the product when it’s added to cart?

        We want to show like a “This item will be delayed X amount of time” for some specific products and we need to change this text for every Product…. Maybe with an ACF field?

        Let me know if you can help me!!
        Have a nice day!

        1. Hi Juan, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  4. Hi Rodolfo,
    Thanks for all you do, love your website! This one isn’t working for me, I tried adding it to a category as described in a comment above, I wonder if it didn’t work because most of my products are in multiple categories?
    Reading some other comments I came across the suggestion to VeggieShirts (love that!) of putting some extra info in a tab and since I was actually planning to use this to say something about ‘10% to charity’ and probably a link the tab idea would be a way better solution, do you happen to have a tutorial on this? I didn’t see one, I’ll look around some more πŸ™‚

  5. Hi, how do I add checkbox next to the text? Many thanks

    1. Henry, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

    2. Cost price for this?

      1. Hi Henry, sorry just saw this now. Please email me at info@businessbloomer.com and I’ll give you an estimate. Many thanks πŸ™‚

  6. Awesome post, just what I was looking for. Instead of echoing text, how would I provide a link? I make jewelry and want to provide a popup of how to size bracelets. Thanks much!

    1. Hey Tania, thanks for your comment! You can echo any HTML, including an “a” tag πŸ™‚

  7. Not appearing above add to cart, it is appearing above the variations.

    1. Thanks for your comment David! Try to use a number greater than “20” in the add_action call. Try with 30, 40, 50, 60 etc until you have it where you want πŸ™‚ Let me know!

  8. Hi, Rodolfo!

    I want to use this code:
    if ( $product->regular_price > 50 ) {
    // run function
    }

    But I cant understand how to combine it with function:
    add_action( ‘woocommerce_single_product_summary’, ‘return_policy’, 20 );

    function return_policy() {
    echo ’30-day return policy offered. See Terms and Conditions for details.’;
    }

    Can you show me exemple? I think it should be easy, but I can not.

    1. Hey Mike, thanks so much for your comment! Just put the “echo” part inside the IF statement πŸ™‚

  9. Hi ,i want to add secure payment logos just below add to cart , any thought?

    1. Hi Zaheer! Instead of echoing text, echo the HTML of the image πŸ™‚ That’s it!

  10. this codes works but It applies to all the products I want to show this to specific product and that text should be below image. can you do that .. thank you

    1. Hey Rocket, thanks so much for your comment! I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know πŸ™‚

  11. Hello,

    I used the code and it shows correctly, however i’d like the “Terms and Conditions” to be a link so the customer can click and view the terms. Is this possible?

    Thanks.

    1. Actually figured it out, thanks in advance. I’m now looking to add text below the add to cart button and i’m using the below code. Everything seems correct but it adds the text next to the cart button not below. Any idea why?

      Thanks.

      1. Hey RK, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  12. Hello,
    If I want to change the position of the content, how can I change this script? For example I want to show something after product title.
    Thank you very much!

    1. Hey Joe, thanks for your comment! I’d recommend you watch my customization tutorial here: https://businessbloomer.com/woocommerce-customization-single-product-page and then take a look at the single product page hooks here: https://businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/. Let me know πŸ™‚

  13. okay i have this in my functions.php file

     
     add_action('after_sold_by_text_cart_page','after_sold_by_text_cart_page_callback');
    	function after_sold_by_text_cart_page_callback($vendor){
    		global  $WCMp;
    		global $woocommerce;
    		$items = $woocommerce->cart->get_cart();
    		
            foreach($items as $item => $values) { 
                $_product = $values['data']->post; 
                $price = get_post_meta($values['product_id'] , '_price', true);
    			$values['product_id'];
    			$pdtid =$values['product_id'];
    			echo '<br>';	
    			//get data from databse
    			global $wpdb;
    			$author_vendor = $wpdb->get_var("SELECT  some_id FROM tablename WHERE ID = '".$pdtid."'");		
    			$vendor_id= $author_vendor ;
    			echo '<br>';
    			$Add = 'Address: ';
    			$city = 'City: ';
    			$tel = 'Phone: ';
    			echo $test;
    			$user_id = $vendor_id;
    			$meta = get_user_meta( $user_id );
    			$meta = array_filter( array_map( function( $a ) {
    				return $a[0];
    			}, $meta ) );
    			
    			echo $Add;
    			print_r( $meta ['_vendor_address_1'] );
    			
    			echo '<br>';
    			
    			echo $city;
    			print_r( $meta['_vendor_city'] );
    			
    			echo '<br>';
    			
    			echo $tel;
    			print_r( $meta['_vendor_phone'] );	
    		} 	
    	} 
    

    So what i want to do is show these addresses on the cart page . and they do . however since i have different vendors for each product i want each product to have only its vendors address. right now each product is getting all the the vendors address for all vendors which is wrong. what can i do to rectify that?

    1. Patrick, thanks for your comment! Unfortunately this is custom work (and it’s not even my snippet) and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

  14. Is it possible to add a condition for price? Say, if price is greater than $50, then show text “This item qualifies for Free Shipping” ?

    Thanks.

    1. Of course! You can check what the price of the product is by adding a conditional check, something along the lines of:

      if ( $product->regular_price > 50 ) {
      // run function
      }
      
      1. Thanks, but does this work with variable products?

        1. Hey Vuster, thanks for your comment! Yes, it works for variable products as well πŸ™‚

  15. hi dear friends
    i want to add the β€œQuantity” word to the side of the box that displays the number in product pages.
    for example-> this link:
    https://www.meroeh.com/product/lovely-baby-dining-table/

    I had done it in the past and Ω‡t worked properly, but But I updated woocommerce and β€œQuantity” word is disappeared and now I can not make it.

    I had done in the past by β€œp” tag, but now i do not know where it was written.

    can you help me pleaseee?

    1. Hey Sara, thanks for your comment! I recommend you watch this tutorial (https://businessbloomer.com/woocommerce-customization-single-product-page/), which should help you remember what you need to do! Let me know πŸ™‚

  16. I want to add accept terms and conditions button above add to cart button so when user check this box so product can be add in cart otherwise error message that you must need to accept terms and conditions.
    Can you please help me about it?

    Regards

    1. Ali, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide you with a complementary solution here on the blog. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  17. Hello Rodolfo,
    Great tutorial! I’m selling virtual products some of them are downloadable some of them aren’t. So I’m trying to add a statement only on my downloadable product page is it possible? (I tried this code it’s adding the statement on all products)

    Thanks

    1. Thank you Suman! Yes, take a look at https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/, and specifically in the section that says “do something if product is simple, variable, external…” πŸ™‚

  18. At the moment i’m building a new webstore for organic, eco-friendly t-shirts (and made without child labor) and found your tutorial. Thank you very much! Your example text is very good choosen, too. Looks very good placed on my site! Perfect! No edit, nothing. Just this super short tut. Very cool.

    This are the small things, how to build/demonstrate trust. I will add a link to the TOS there, too. Sure, a new way to click away from the sale when i add a link there, but i think not much people will click there… and if they click it’s ok if they are looking for trust (and find it). Then they will come back, cause they realize the quality af the shop, the project and so on (i hope so).

    Do you include there a link for your projects/clients, too? Do you think it’s important/worthy? (Look, we have nothing to hide! Trust us! [ok, answered by my self]) Do you have experience how many percent will click there and so on? How do you think about all this?

    Brings me to the next point: write the TOS… Something nice looking, nothing ugly-to-read. I think it’s very important, too. My opinion is: show clear and transparent that anybody can look inside and find the trust.

    Thanks again. I’m really looking forward to study your website (infos in the sidebar looked interesting + this worty tutorial here)! I think with you in my shop there is a lot of more optimization/money/attention for the project possible.

    1. Cheers VeggieShirts for your very long comment πŸ™‚ I’d recommend to leave the TOS on the checkout page, and maybe put additional tabs on the single product page to increase conversion, such as “why Veggie?”, “how we make it without child labor”, etc πŸ™‚ Best of luck!

      1. Hey Rodolfo. Thanks for your answer and your inspiration! The tab is a good idea. I think there are a lot of possibilities to promote this and i think it’s very important for me and my customers. Should be arguments to buy there. Thank you for the wishes! I think (and hope) we will read us later again.
        (y)

  19. Hi, great tutorial.

    I wonder if it is possible to add an array of product ID’s that would make it show on all product pages except the ones defined?

    1. Hello Brian, thanks for your comment! Of course, anything is possible with PHP πŸ™‚ Hope you find the solution! Cheers πŸ™‚

      1. After much deliberation I’m still non the wiser. Please help.

        1. Brian, thanks so much for your follow-up! What I meant in the previous comment is that unfortunately this is custom work and I cannot provide a complementary solution here on the blog. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  20. Thanks for the help (Y)

    1. You’re very welcome Mazedul! Thanks for your feedback:)

  21. This snippet adds it right below the price, even before the summary and select size dropdowns. How do I add it either after the summary, before the size dropdowns, or after the select size dropdowns, before the add to cart?

    1. Hey James, thanks for your comment! Simply trying playing with the “20” inside the add_action. Change it to a higher number, such as “80” and see if it shows in the position you want it πŸ™‚ Let me know!

  22. Great stuff. And easy enough to implement for a beginner like me.
    Any easy way to have it show a login form for visitors?

    1. Thanks Lodix, much appreciated! Uhm, what about just showing a link to the “My Account” page?

      1. Hi Rodolfo,
        Thanks for the suggestion. I thought of that too, but there are two reason why that doesn’t work for me:
        1) the link will show even when the shopper already logged in.
        2) clicking the link would direct the shopper away from the product page. After they log in they would have to find the product again through the shop page. I prefer they log in on the product page.

        1. Lodix, I’m glad to say “there is always a way”!

          1) you can show the link conditionally – “if user is logged in”, show no link
          2) you can add a “referrer” parameter when you send people to the My Account page – upon login they will be redirected to the previous page (product page in this case)

          Hope this helps!

          1. Great tips. That would certainly work.

            I already found a snippet for the second point you mentioned. I need to do some googling for a snippet that shows the link conditionally. It sounds easy enough, but since I am not a coder I reply on ready made snippet like the awesome code you posted on this page. So please keep sharing and I will be sure to read more articles on this site πŸ™‚

            1. Excellent, thanks for the follow-up!

  23. Thank you for that!
    Was very helpful in order to put a “on vacation” notice.

    Thanks a lot.

    1. Fantastic David, thanks a lot πŸ™‚ And happy holidays!

  24. I actually want to insert a Banner below the Add to cart button. This banner should be different for each product. Can I still use this snippet? If yes please help me.

    1. Hey Sujal, thanks for your comment!

      Yes, you can just change the “priority” to place it below the Add to Cart. Try using “35” instead of “20”.

      In regard to having this behave differently for each product, it really depends on how many products you have. If you have 5-10 only, you can use conditional logic. Otherwise, you should use custom fields and echo their value on the single product page (similarly to https://businessbloomer.com/woocommerce-show-product-custom-field-in-the-category-pages).

      Hope this helps!

  25. Hay, I do not have good knowledge of programming can you please let me know how can I add a custom text for every single product page as COD is available with green check box or something like that?

    1. Hey Mohammad, thanks for your comment! I’m afraid I don’t offer free customization of my snippets. This task would be pretty easy to accomplish. Take a look at Fiverr or other freelancing platforms if you’re on a low budget. Hope this helps!

  26. Very helpful tutorial Rodolfo. This helped out greatly! However, I have a gravity form on my product page to customize the order and the β€˜30-day return policy’ text is shown above this form, not above the add to cart button where I want it. Is there a way to fix this?

    Note: I used the exact snippet and added the css customization in your tutorial.

    1. Hey Matthew thanks for your comment πŸ™‚ All you need to do is playing with the “20” inside the add_action. That is the hook priority and defines the position. Try changing it to 11, or 35, depending on where you want that to show πŸ™‚

      1. Thank you Rodolfo! That fixed my problem!

  27. Hi Rodolfo,

    For some strange reason adding the above code does nothing. I do not get the text appearing anywhere on the single product page. Has anything changed in the recent version of Woocommerce?

    Woocommerce: I am using Version 2.5.5 the latest version as of today.
    WordPress: Version 4.4.2

    1. Hey Nick thanks for your comment πŸ™‚ I just tested this on my Woo 2.5.5 and it works perfectly so take a look at the following:

      1) Do you have a cache plugin? Clear the cache and see if the text appears

      2) Is your theme or other plugins removing the “woocommerce_single_product_summary” action? I doubt, but do a file search for remove_action(‘woocommerce_single_product_summary’ to see if anything comes up

      3) Do you have a theme/plugin conflict? Disable all plugins but Woo and switch theme temporarily: is the text appearing?

      4) I hope this is given for granted: have you added the snippet to the functions.php file of your child theme?

      Hope this helps πŸ™‚

      1. Hi Rodolfo, thank you for your reply.

        Looks like my theme is the issue. I tried with TwentySixteen and it seems to work fine. I did get a message when I was installing WC, that the theme files are outdated. I will check with the developer regarding this.

        Btw, could you explain what exactly is the number for? The number in the add_action part? I don’t seem to get it.

        Thanks again!
        Cheers

        1. I see πŸ™‚ Thanks for reporting back! In relation to the add_action “number”, that’s called priority. You can find the theory here: https://developer.wordpress.org/reference/functions/add_action.

          Basically, if you have the following case:

          
          add_action( 'woocommerce_single_product_summary', 'function_A', 20 );
          add_action( 'woocommerce_single_product_summary', 'function_B', 30 );
          
          

          … whatever is generated by function_B will show UNDER whatever is generated by function_A.

          Priority defines the “execution order” = the position πŸ™‚

          Hope this helps!

  28. Rodolfo, what about if I want to put an “all on-sale sales items are final” only on those products that are on sale? thanks

    1. Hey Hector thanks for your enquiry! I think the solution here is very simple, just add this conditional logic:

      
      global $product;
      if ( $product->is_on_sale() ) {
         // run the function here
      }
      
      

      Hope this helps πŸ™‚

      R

  29. Thanks for this πŸ™‚

    Anyway we can show this message only on certain categories?

    We want to show a message above cart on single pages in our mobile phone category page.

    Would love some help if possible πŸ™‚

    1. Cheers Ran πŸ™‚

      Of course – you can just use the conditional tag has_term:

      
      // say "audio" is your category slug:
      
      if ( has_term( 'audio', 'product_cat' ) ) {
      
      // run function
      
      }
      
      

      Hope this helps πŸ™‚

  30. What if i want to add it to my cart page+for certain product or product category?

    1. Dzulhelmi, thanks so much for your feedback! Yes, this is possible – but unfortunately it’s pretty custom and I cannot provide this solution on the blog. If you would like to get a quote, feel free to go here. Thank you! R

  31. Hi What if i wanted to add text below the price on all products in the category page? Could i use your code?

  32. Great tutorial! I am trying to use the following code but it isn’t working. Can you help?

    if ( is_product_category( ‘oils’ ) ) {

    add_action( ‘woocommerce_single_product_summary’, ‘safety’, 20 );
    function safety()
    { echo ‘Testing 1’; }

    }

    If I add the code without the if statement it shows fine on each product page. Am I doing the if command correctly?

    1. Ryan, have you tried this:

      add_action( ‘woocommerce_single_product_summary’, ‘safety’, 20 );

      function safety() {
      if ( is_product_category( ‘oils’ ) ) {
      echo ‘Testing 1’;
      }
      }

      Note: this will work exclusively on the Archive page of your “Oils” category.

      1. Thanks. Unfortunately this code doesn’t work for me. I’m not sure what you mean by the “archive page”, I am looking to have this code on the single product page for every item in the Oils category

        1. Hey Ryan, thanks for your comment. Just wondering if you posted on the right page? This snippet is for the single product page – if it doesn’t work for you feel free to copy/paste your snippet and I’ll take a look. Cheers!

          1. Here is the code I am using:

            add_action( ‘woocommerce_single_product_summary’, ‘safety’, 20 );

            function safety() {
            if ( is_product_category( ‘essential-oils’ ) ) {
            echo ‘Testing 1’;
            }
            }

            I have a category with the slug essential-oils so in theory it should work fine. Perhaps I have some errors in my code or something.

            If I use this code without the if statement it works (on every product in the shop)

            add_action( ‘woocommerce_single_product_summary’, ‘safety’, 20 );

            function safety() {
            echo ‘Testing 1’;
            }

            1. Ryan, “is_product_category” only works on the shop/category page. If you are working on the single product page the snippet will be different. Anyway, we’re off topic here so maybe contact me as this post is about the Cart page. Thank you!

  33. Good to find you here. ^.^

    Can I use WC conditional tag wrap your snippets for specific category?

      1. Never received you reply email too

        I am not luck, cannot make it work. May be my theme issue.

        Anyway thanks

        1. Sorry! Is worked but not in above the add-to-cart, its was in my bottom of product short category.

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *