• Resolved oliver7772

    (@oliver7772)


    Hey Support Team/Community,

    Hope you are well. I’m stuck with one of my clients’ sites. I would like to display feature icons. This means that if a product has a specific tag it would = display a specific icon. I wasn’t sure what is the best approach for this is.. I have a custom elementor site/not themed so I thought I should do it over the small summary..

    Could you guys help to complete it? Not sure where to end it… I know how to display all the icons if there is more than one tags.. Initially I thought about lists/arrays but not sure now..

    Here is my nooby code:

    function magik_custom_text( $post_excerpt ) 
    {	
    	$socialcontribution = '';
    	$naturalingredients = '';
    	$veganfriendly = '';
    	$plasticfree = '';
    	$recycleable = '';
    	$sustainable = '';
    	$handmade = '';
    	$madeinuk = '';
    	$refillable = '';
    	$organic = '<i class="fab fa-500px"></i>
    
    ';
    	
    	$thelist = array();
    	
    	if ( has_term( 'organic', 'product_tag' ) ) {
    		$thelist[] = $organic;
    		return $thelist[0] . '<br><br>' . $post_excerpt;
    	} elseif ( has_term( 'refillable', 'product_cat' ) ) {
    		return $refillable . '<br><br>' . $post_excerpt;
    	} else {
    		return $content . '<br><br>' . $post_excerpt;
    	}
    	
    }
    add_filter('woocommerce_short_description', 'magik_custom_text', 10, 1);

    Every help helps… Thank you ??

    Oliver

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support con

    (@conschneider)

    Engineer

    Hi Oliver,

    I would start by simplifying your function. Too many control statement (if…) and too many variables can lead you astray quickly.

    Start with something like `if ( has_term( ‘organic’, ‘product_tag’ ) ) { $mytag = ‘<i class=”fab fa-500px”></i>’ return $mytag;}

    Then gradually expand that code 1 step at a time to see where it fails.

    Kind regards,

    Thread Starter oliver7772

    (@oliver7772)

    I have no idea of this.. it doesn’t even accept the the code unfortenately..:(

    Thread Starter oliver7772

    (@oliver7772)

    Mirko P.

    (@rainfallnixfig)

    Hi @oliver7772,

    Just wanted to offer some more options here. You can visit the WooCommerce Facebook Community group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Thanks!

    Mirko P.

    (@rainfallnixfig)

    Hi there,

    Just a heads up, we’ve not heard back from you in a while so I’ll go ahead and mark this thread as resolved. Hopefully, you were able to find a solution to this issue.

    If you have further questions, please feel free to open a new topic.

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to display an Icon on Single Page if a Product Has A Specific Tag’ is closed to new replies.