Have you tried has_category
? You can add a check to make sure the post has the specified category. If not then return the content un changed like below:
<?php
add_filter( 'woocommerce_short_description', 'wpse_67108_autplay_music' );
function wpse_67108_autplay_music( $content ) {
if ( ! is_singular( 'product' ) && ! has_category( '<your specific category here>' )) {
return $content;
}
$audio_files = get_children(
array (
'post_parent' => get_the_ID(),
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'audio'
)
);
$audio = '';
if ( $audio_files )
{
$id = array_pop( array_keys( $audio_files ) );
$url = wp_get_attachment_url( $id );
// add a 'controls' attribute to enable controls
$autoplay = in_category( 'premium' ) ? 'autoplay' : '';
$audio = "<audio src="https://wordpress.stackexchange.com/questions/383900/$url" controls controlsList="nodownload" $autoplay loop></audio>";
}
return $audio . $content;
}