Display the product category under product title on the shop in WooCommerce

Display the product category under product title on the shop in WooCommerce on child sites.

Snippet Type

Execute on Child Sites

Snippet

function product_category_in_shop_loop() {
    global $product;
    $product_id = $product->get_id();
    $cat = wp_get_post_terms($product_id, 'product_cat', array('fields' => 'names'));
    if( !empty($cat[0]) ){
       echo '<p class="catil">'.$cat[0].'</p>';
    }
}
add_action( 'woocommerce_after_shop_loop_item_title', 'product_category_in_shop_loop', 40 );