145 posts
  • Austria
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 1-2 years
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

3364 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Community Moderator
  • Bought between 50 and 99 items
  • Referred more than 2000 users
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+4 more
sevenspark Volunteer 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
  • Austria
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 1-2 years
LovelessDesign says

Thanks. That helped :)

3364 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Community Moderator
  • Bought between 50 and 99 items
  • Referred more than 2000 users
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+4 more
sevenspark Volunteer 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

by
by
by
by
by
by