How to target parent product category and its children using WooCommerce?

the WordPress function cat_is_ancestor_of() is made for WordPress categories, but not for WooCommerce product categories which is a custom taxonomy product_cat.

For Custom taxonomies you can use WordPress term_is_ancestor_of() function like:

term_is_ancestor_of( 19, get_queried_object_id(), 'product_cat' )

So in your code:

if ( is_product_category( 'foo-category' ) || term_is_ancestor_of( 19, get_queried_object_id(), 'product_cat' ) ) { 
    wc_get_template( 'archive-foo.php' );
} else { 
    wc_get_template( 'archive-product.php' ); 
}

This time it should work.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)