There are two ways of doing this - with hooks, or by overriding the WooCommerce template file in your Child theme. First, let's look at the file override:
Method 1 - File Override
From the WooCommerce plugin folder, copy the templates/single-product/title.php
file, and paste it into your active theme under woocommerce/single-product/title.php
Then, simply change this line:
the_title( '<h1 itemprop="name" class="product_title entry-title">', '</h1>' );
to:
the_title( '<h2 itemprop="name" class="product_title entry-title">', '</h2>' );
Method 2 – Using Hooks
We find in the template file content-single-product.php
that the function we need to override is called woocommerce_template_single_title
:
/**
* Hook: woocommerce_single_product_summary.
*
* @hooked woocommerce_template_single_title - 5
* @hooked woocommerce_template_single_rating - 10
* ...
WooCommerce template functions are defined in includes/wc-template-functions.php
, and this function looks like:
if ( ! function_exists( 'woocommerce_template_single_title' ) ) {
/**
* Output the product title.
*/
function woocommerce_template_single_title() {
wc_get_template( 'single-product/title.php' );
}
}
What we're going to do is unhook that action, then hook in our own function - just add this code to your functions.php
file and make any changes to the heading tags in the the_title()
function:
remove_action( 'woocommerce_single_product_summary','woocommerce_template_single_title', 5 );
add_action('woocommerce_single_product_summary', 'your_custom_function_call', 5 );
function your_custom_function_call() {
the_title( '<h2 class="product_title entry-title">', '</h2>' );
}