How can PHP be used to set filtered pages to noindex for SEO purposes in a WordPress Woocommerce product catalog?

To set filtered pages to noindex for SEO purposes in a WordPress Woocommerce product catalog, you can use PHP to add a meta tag to the header of the filtered pages. This meta tag will instruct search engines not to index those pages, which can help prevent duplicate content issues and improve SEO.

function add_noindex_meta_tag() {
    if (is_product_category() && isset($_GET['filter'])) {
        echo '<meta name="robots" content="noindex">';
    }
}
add_action('wp_head', 'add_noindex_meta_tag');