Conditional logic – if product has a parent category, echo this

There are two files that WooCommerce pulls from to create a product page: single-product.php and content-single-product.php.

Single-product.php determines what information is displayed on the page and creates the layout that will display the information. You can view its content here.

Content-single-product.php pulls the content of the product that’s been organized into hooks with actions and filters, and nests those into the single-product.php layout. You can view its content here.

In order to make sure that WooCommerce doesn’t erase any customizations that you make, you’ll need to make copies of each of these files and put them in a /woocommerce folder in your child theme.

You will basically have to use content-single-product.php and add your code there, I don’t really know where do you want to display it, so I cannot tell where.

In order to check if a product has Parent Category, you could use this answer, which returns the parent categories, so in your case, if the return is an empty array you don’t have parent categories, but if it’s not empty use it on your echo.