Menu Close

WooCommerce: Capitalize All Product Names

default

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        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 7
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

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;
}
View Source
Posted in WooCommerce Tips