Viewing 7 replies - 1 through 7 (of 7 total)
  • Depends. Should all products have the mark, or only certain ones?

    Thread Starter souravkr

    (@souravkr)

    hey lorro,

    thanks for reply,
    for selected product(s).

    How can the selected products be identified? Can they all be in the same category?

    Thread Starter souravkr

    (@souravkr)

    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

    • section.

      or can we show as a text like veg or non-veg!

    Thread Starter souravkr

    (@souravkr)

    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="https://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.

    Thread Starter souravkr

    (@souravkr)

    hey lorro,

    thank you so much.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Vegetarian Mark’ is closed to new replies.