Hi,
I guess the Code in that article is writing to the database.
A better solution would be to generate the attribut links, when a product page is opened.
AND
Only for those attributes that make sense to be clickable.
With the following code sample and a proper configuration of the search extention Relevanssi or any other search extention, the clickable link will take the clicked term and redirect to the search page with the products listed that share the same search term.
Use this code in a child-theme functions.php OR the plugin Code Snipped.
I recommend Code Snipped.
/**
* Make specific custom attributes clickable links and ignore non-alphabetic words in German.
*/
function make_specific_attributes_links( $attribute_html, $attribute, $values ) {
$specific_attributes = array(
‘Kultivar-Model’,
‘Japanisches Wort’
);
// Check if it’s a custom attribute (not a global attribute) and is in the specific attributes list
if ( ! $attribute[‘is_taxonomy’] && in_array( $attribute[‘name’], $specific_attributes ) ) {
$attribute_values = array();
foreach ( $values as $value ) {
// Check if the value contains only alphabetic characters (German)
if ( preg_match( ‘/^[a-zA-Z??ü??ü?]+$/’, $value ) ) {
// Create the search URL
$search_url = home_url( ‘/?s=’ . urlencode( $value ) . ‘&post_type=product’ );
// Generate the clickable link
$attribute_link = ‘‘ . esc_html( $value ) . ‘‘;
// Add the clickable link to the array of attribute values
$attribute_values[] = $attribute_link;
} else {
// Non-alphabetic value, add it as plain text
$attribute_values[] = esc_html( $value );
}
}
// Implode the attribute values with the original separators
$attribute_html = ” . implode( ‘, ‘, $attribute_values ) . ”;
}
return $attribute_html;
}
add_filter( ‘woocommerce_attribute’, ‘make_specific_attributes_links’, 10, 3 );