WooCommerce: Capitalize All Product Names

When you deal with WooCommerce websites, you also need to look into design, readability, and accessibility. And if you have hundreds or thousands of products, you probably need to set some global rules so that you don’t need to worry about editing each product manually.

One rule could be the way product titles are displayed. Maybe you have a mix of capitalized product names (“Red Square Table”), non-capitalized ones (“White round chair”) and all caps ones (“GREEN COUCH”), and therefore you’re looking for a PHP shortcut to fix this automatically.

So, here’s a super simple solution to capitalize all product titles. Enjoy!

To make the product titles uniform on this website, I’d like to show a capital “Y” and capital “B” in this product title. But I don’t want to do it manually. Here’s a quick PHP fix that allows you to capitalize all product titles automatically.

PHP Snippet: Capitalize Product Titles @ Shop & Single Product Pages

/**
 * @snippet       Capitalize Product Title @ Shop, Single Product
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 7
 * @community     https://businessbloomer.com/club/
 */

add_filter( 'the_title', 'bbloomer_capitalize_single_prod_title', 9999, 2 );

function bbloomer_capitalize_single_prod_title( $post_title, $post_id ) {
	if ( ! is_admin() && 'product' === get_post_type( $post_id ) ) {
		$post_title = ucwords( strtolower( $post_title ) );
	}
	return $post_title;
}

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

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

2 thoughts on “WooCommerce: Capitalize All Product Names

  1. Hi Rodolfo,

    Thanks for your snippet. Exactly what I was looking for, something without a plugin. However it would be great if you could help me with a version which Capitalises the entire title and not just the first letters. Would really look forward to that.

    Also, I was looking at doing the capitalise part for other sections as well, eg. Sidebar Titles, Product attribute filters and other woocommerce elements. Is there a script which could help me do that globally or element wise. Where probably I could just change the element ID for example?

    Really looking forward.

    1. Vaibhav, 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!

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 *