is_page_template() does not work inside a WordPress loop.
Most likely, the point is this and the test must be moved out of the cycle.
You can try to figure out the template used in an alternative way, through the page's meta-fields:
if ( get_page_template_slug( get_the_ID() ) == 'content-main.php' ) {}
The second method should work inside the loop.
UPDATE
The second method works for a cycle through pages, and WooCommerce performs its cycle by product, and get_the_ID() does not work here. In the case of WooCommerce, you can determine which template to use as follows.
In functions.php add a filter that tracks the change of the template and stores it in a global variable, as well as a function that returns the value of this global variable.
function filter_template_include( $t ) { $GLOBALS['current_template'] = basename($t); return $t; } add_filter( 'template_include', 'filter_template_include', 1000 ); function get_current_template() { if( !isset( $GLOBALS['current_template'] ) ) return false; return $GLOBALS['current_template']; }
In the content-product.php file, use this function to get the name of the current template.
if (get_current_template() == 'content-main.php') {}
I remind you that it is better to copy content-product.php to the subfolder of your theme /wp-content/themes/my-theme/woocommerce/ and edit there. So it will remain when updating WooCommerce.
For the test page was created on the test site. She is assigned a woo-test template. Contents of the file so632379.php
<?php /* Template Name: woo-test */ echo do_shortcode('[products]'); ?>
In the content-product.php added line output template name
// Ensure visibility if ( empty( $product ) || ! $product->is_visible() ) { return; } echo "Current template = " . get_current_template(); ?> <li <?php post_class(); ?>>
The result is here .
