145 posts
  • 3 Years of Membership
  • Austria
  • Collector Level 1
  • Exclusive Author
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

3535 posts
  • Power Elite Author
  • Author Level 12
  • Trendsetter
  • United States
+13 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
  • 3 Years of Membership
  • Austria
  • Collector Level 1
  • Exclusive Author
LovelessDesign
says

Thanks. That helped :)

3535 posts
  • Power Elite Author
  • Author Level 12
  • Trendsetter
  • United States
+13 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

1 post
  • 1 Year of Membership
  • Collector Level 1
  • New Zealand
abhims2
says

wonderful. Solved my problem too. :)

by
by
by
by
by
by