145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

Hello I would need a php syntax expert for a short question.

It’s in the WooCommerce Plugin. There are product attributes which all have an ATTRIBUTE NAME and a VALUE. Every value is divided by comma. Now, I want to just add Links to every by comma divided value.

This line is at the bottom in product-attributes.php:

echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );

Every Value should have a link to a glossar, for example the value “Game” should have a link like http://xxx.com/glossar#game>

echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( '<a href="http://xxx.com/glossar#game">'.implode( '</a>, <a href="http://xxx.com/glossar#game">', $values ).'</a>' ) ), $attribute, $values );

How can I change it so that the word “game” in the link is always the actual value? It doesn’t work with something like $values or $values0

Would be great if someone could help

3503 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $750,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark Moderator says

Why can’t you just iterate over the array values beforehand?

foreach( $values as $key => $val ){
  $values[$key] = '<a href="http://xxx.com/glossar#game">'.strtolower( $val ).'</a>';
}

Though depending on the scenario/context of this code, you should probably be doing it all in a separate filter anyway.

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

Thanks. That helped :)

3503 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $750,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark Moderator says

You’re welcome :) And I realized I forgot the important part

foreach( $values as $key => $val ){
  $values[$key] = '<a href="http://xxx.com/glossar#'.strtolower( $val ).'">'.$val.'</a>';
}

haha

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by