WooCommerce Show Banner On Specific Product Archive

Pre-Requisites

There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About this Solution

Showing a banner on the product archive template is a great way to capture the customer’s attention as they browse through your products. This guide shows you how you can show such a banner on a specific category and not on others. This is particularly useful if you’re running a sale only on one product category only or perhaps you need to give customers information about the products on the category as a whole. Simply change the product category slug, the HTML message, and the CSS styling of the message as needed.

				
					/**
 * Snippet Name:	WooCommerce Show Banner On Specific Product Archive
 * Snippet Author:	ecommercehints.com
 */

add_action( 'wp_head', 'ecommercehints_specific_product_archive_banner' );

function ecommercehints_specific_product_archive_banner() {

if ( is_product_category( 'accessories' ) ) { // The product category to show the banner ?> 

<style>
	.ecommercehints_category_banner {
		background-color: blue;
		color: white;
		font-size:20px;
		text-align:center;
	}
</style>

<?php echo '<div class="ecommercehints_category_banner">Accessories Sale Ends Tonight!</div>';
}

}
				
			

Snippet Benefits

  • Show a custom message only on one product category
  • Let users know of a sale running for a specific category.
  • Display product category specific information on the relevant archive template.
WooCommerce Conversion Rate Optimisation (CRO) eBook
100 WooCommerce Conversion Rate Optimisation Tips

Leave a Reply

If you are going to write code in the comments, please wrap it between code tags.

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

Other Recent Guides

Subscribe To Emails

Get exclusive WooCommerce tips that I only share with email subscribers

Join hundreds of other subscribers