Including css in php file

Hi,

I’m trying to include a css file in app/woocommerce.php

I’ve added the css file to config.json in resources and created the file which has my css. Im trying to include it in a function like so:

/**
 * @snippet       Add CSS to WooCommerce Emails
 * @since 1.1
 */
add_action( 'woocommerce_email_header', function() {
    ?><style>
        <?php include asset_path('styles/emails.css'); ?>
    </style><?php
});

but this doesn’t work. However, just writing the css into the function does work. What am I doing wrong?

asset_path() returns a URI, which include() cannot…include without some additional settings (also, IMO it’s not a great ideal to load URLS into code that gets executed, esp. if they’re available on the local filesystem). You can get the the correct filename (i.e. hashed or not hashed) with sage('assets')->get('asset_name.ext') and then concatenate that with whatever the path is for your rendered asset, i.e. get_theme_file_path().'/dist'.