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!
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
* @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;
}