Display Additional Content on WooCommerce Shop Page

In this blog post, we will see how to display some additional information on the Shop/Archive/Category page using WooCommerce hooks and good ole PHP. I saw a question similar to this asked recently in a WooCommerce FaceBook group and thought to try my hand at a working solution. Here is what I learned and came up with…

The Newsletter for PHP and MySQL Developers

Receive a copy of my ebook, “10 MySQL Tips For Everyone”, absolutely free when you subscribe to the OpenLampTech newsletter.


Note: All of the examples in this post are part of a development/learning WooCommerce install using the default Storefront theme. PHP code is placed in the child theme’s function.php file.


For this example, I am targeting the area on the Shop page just above the sorting dropdown and pagination. Perhaps you could display some banner text here about your shop or any other relevant information.

In order to have a more styled text display, I have added this minimal CSS to the child theme’s style.css file:

.woo-custom-info-on-shop-page-style {
text-align: center;
font-size: 19px;
padding-bottom: 10px;
}

WordPress and therefore WooCommerce, are full of action and filter hooks. For this requirement, I am targeting the woocommerce_archive_description hook:

add_action( 'woocommerce_archive_description', 'woo_custom_info_on_shop_page', 4);

function woo_custom_info_on_shop_page()
{
if ( ! is_shop() ) return;

echo "<div class='woo-custom-info-on-shop-page-style'><span>Some additional text here</span></div";
}

I want to be sure this code executes only on the Shop page (which could include the Category and Archive pages too) therefore, I use the is_shop() function in an if() conditional, and if the current page is not the Shop page, then just return from the code, essentially doing nothing:

As shown in the screenshot above, the additional text is displayed just before the sorting and pagination on the Shop page.

Credit Resources

The following resource (and site in general) are a goldmine of useful WooCommerce knowledge. In particular the visual hook guide page(s):


If you see any mistakes in the code or know of a better solution, please share them freely in the comments section.


Thank you for reading this post. Please share it with someone else who would enjoy it as well.


Josh Otwell has a passion to grow as a PHP Developer, SQL expert, and technical blogger/writer.

Disclaimer: The majority of examples in this post, are performed in a personal development/learning workstation environment and should not be considered production quality or ready. Your particular goals and needs may vary. Like always, just because you can do something doesn’t mean you should. My opinions are my own.

More ways I can help

Disclosure: Some of this blog post’s services and product links are affiliate links. At no additional cost to you, should you make a purchase by clicking through one of them, I will receive a commission.

The Newsletter for PHP and MySQL Developers

Receive a copy of my ebook, “10 MySQL Tips For Everyone”, absolutely free when you subscribe to the OpenLampTech newsletter.


πŸ“° Get your brand, product, or service the attention it deserves with affordable classified ad placement in the OpenLampTech newsletter. I appreciate your support!


Hey thanks for commenting! Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.