Depends. Should all products have the mark, or only certain ones?
hey lorro,
thanks for reply,
for selected product(s).
How can the selected products be identified? Can they all be in the same category?
hi lorro,
thanks for reply.
Yes of course, suppose i have a food category and it’s subcategory is veg and non-veg. When we select veg than show a green symbol and when we select non-veg than show a red symbol anywhere around the product
or have any alternative solution for differentiate the food… so, user can understand easily that food is veg or non-veg using woocommerce plugin extension, or woocommerce hook?
thankyou.
Add this to functions.php for your child theme:
add_action( 'woocommerce_before_shop_loop_item_title', 'show_mark', 15 );
add_action( 'woocommerce_before_single_product_summary', 'show_mark', 15 );
function show_mark() {
global $post;
$my_cat_id = 16; // category id kits
$terms = get_the_terms( $post->ID, 'product_cat' );
$found = false;
foreach ($terms as $term) {
if ($term->term_id == $my_cat_id) {
$found = true;
break;
}
} // end for
if ($found) {
print '<img src="http://www.abcd.co.uk/wp-content/uploads/lightbulb.jpg" class="my_mark" />'.PHP_EOL;
}
}
You must replace 16 with the id of your veg category.
You must replace the lightbulb.jpg bit with the full path to your veg mark image.
To get the mark in the right place, try this custom css:
.product {
display:relative
}
.product .my_mark {
position:absolute;
left:20px;
top:40px
}
If it doesn’t work, please post the url to a relevant product.