I am using WooCommerce in WordPress and want to automatically add noindex
for out of stock products. Currently I can put noindex
for sold
category by using this code
function add_tagseo_metarob() {
if ('product' == get_post_type()){
if ( has_term( array('SOLD'), 'product_cat' )) {
?>
<meta name="robots" content="noindex">
<?php
}
}
}
add_action('wp_head', 'add_tagseo_metarob');
this code works but I have to manually update the individual product into sold
category.
Is there any similar solution that I can automatically add noindex
for out of stock products?