Understanding wc_get_template_part( ‘content’, ‘single-product’ );

Sometimes either on pure WordPress or on Woocommerce I am trying to follow a function to see where it goes and how it actually works. The good thing about modern editors is that many of them allow you to follow the function. I used to use NotePad++ but a couple of years ago switched to Sublime. One advantage of Sublime is that by placing your cursor over a function it shows a link to the original place. I used this advantage to get to the root of the Woocommer wc_get_template_parts and turns out it is actually referring to wp_get_template_part.

This is what I was trying to figure out:

wc_get_template_part( 'content', 'single-product' );

The function is actually

function wc_get_template_part( $slug, $name = '' )

Apparently based on some conditions it looks for

$template = locate_template( array( "{$slug}-{$name}.php", WC()->template_path() . "{$slug}-{$name}.php" ) );

Which in my case it means


upon another condition looks for

$template = WC()->plugin_path() . "/templates/{$slug}-{$name}.php";

Which in my case would be


And upon the third condition:

locate_template( array( "{$slug}.php", WC()->template_path() . "{$slug}.php" ) );

which would have been


In my case the first condition is true so it returns:

Leave a Reply

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