Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author isabel104

    (@isabel104)

    Hi,

    WooCommerce no longer registers the attributes as custom taxonomies. Creating links was easy when they were taxonomies. There is no easy way to generate a link for these attributes.

    The easiest way to get something similar would be to use product tags. The product tags would be automatically placed on the product page, and they will automatically link to their archive pages.
    I hope that helps.

    MShaner

    (@mshaner)

    Not to sound obtuse, but isabel104 are you saying that since WooCommerce no longer registers the Product Attributes as custom taxonomies there’s not only no easy way to generate a link to these attributes … that there’s also (by extrapolation) no easy way to actually create order(s) based on customer(s) product customization choice(s)?

    Why, then, does WooCommerce not ‘allow’ for custom taxonomies for this very purpose? Or do they via other plug-in(s)?

    Thank you in advance for your time and your clarity.

    Plugin Author isabel104

    (@isabel104)

    To allow a customer to select a product customization, you might want to use Product Variations. Variations allow a customer to select a color, size, or any other type of variation that you set up. See WooCommerce Product Variations.

    Plugin Author isabel104

    (@isabel104)

    You now have the option to show attributes as links (as of version 1.4.2). There are some conditions. Please see the release notes.

    Correction:
    Above, I said:

    WooCommerce no longer registers the attributes as custom taxonomies.

    This is wrong. “Global Attributes” are registered as taxonomies, but “Custom product attributes” are not. Global Attributes are those which are first created in Products -> Attributes. “Custom product attributes” are created directly in the Edit Product page.

    I hope this helps.

    Okay sorry to dig this up but I don’t really see this answered anywhere: how to I make my product attributes clickable? For example I list DVDs and they have languages “German, English”. I want each of those clickable so the visitor sees a list of items with language German, or language English. I can’t well generate Categories for all kinds of attributes, plus… they won’t be listed there either. The same with Tags, they would be confusing without the context “Attribute: Value”

    The answer lies in /plugins/woocommerce/templates/single-product/product-attributes.php

    and someone with better php skills than me oughta be able to modify the code there to make attributes be linked with the help of

    https://biostall.com/listing-linking-and-refining-by-woocommerce-attributes

    and / or
    https://themeforest.net/forums/thread/woocommerce-add-links-to-attribute-values/94924

    and / or

    https://docs.woothemes.com/document/display-product-attribute-archive-links/

    anyone? would greatly appreciate that help. I just cant make sense of these foreach loops, my php skills are too limited

    hi did just assemble a quick solution – might not be perfect e.g variable naming – add to a plugin or to your themes functions.php ( Tested with storefront )

    function links_for_woocommerce_attribute( $content, $attribute, $values) {
    global $product;
    	if ( $attribute['is_taxonomy'] ) {
    		$terms = wc_get_product_terms($product->id, $attribute['name']);
    		$values = array();
    		foreach ($terms as $term) {
    		    $values[] = '<a href="'.get_term_link($term->slug, $term->taxonomy).'">'.$term->name.'</a>';
    		}
    	} 
    
    	return wpautop( wptexturize( implode( ', ', $values ) ) );
    }
    add_filter('woocommerce_attribute', 'links_for_woocommerce_attribute', 11, 3);

    antoher way would be to change the tempalte itself …

    To answer the main question, here is our solution:

    if ( $attribute['is_taxonomy'] ) {
    					$landing = 56; // Product category id if y wanna use that instaed of Shop root
    					$ids = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'ids' ) );
    					$filter_variable = str_replace('pa_', 'filter_', $attribute['name']);
    					$url = get_permalink( woocommerce_get_page_id( 'shop' ) );//get_term_link( intval($landing), 'product_cat' );
    
    					$urls  = array();
    					$links  = array();
    
    					foreach ( $ids as $id ) {
    						$url = add_query_arg($filter_variable, $id, $url);
    						$urls[] = esc_url( $url );
    					}
    
    					$values = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'names' ) );
    					$c = 0;
    					foreach ($values as $name) {
    						$links[] = '<a href="'.$urls[$c].'">'.esc_html($name).'</a>';
    						$c++;
    					}
    					echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $links ) ) ), $attribute, $values );
    
    				} else {
    
    					// Convert pipes to commas and display values
    					$values = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
    					echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );
    }

    I used:

    // Add Hyperlinks to Attributes in Additional Information Tab on Product Page
    add_filter ('woocommerce_attribute', 'rb_link_attributes', 10, 3);
    	function rb_link_attributes($attributes_string, $attribute, $terms) {
    		global $post;
    		$taxonomy = get_taxonomy( $attribute['name'] );
    
    		if ( $taxonomy && ! is_wp_error( $taxonomy ) ) {
    			$attribute_string = '';
    			$terms = wp_get_post_terms( $post->ID, $taxonomy->name );
    
    			if ( !empty( $terms ) ) {
    				foreach ( $terms as $term ) {
    					if (strlen($attribute_string) > 0) {
    						$attribute_string .= ', ';
    					}
    					$archive_link = get_term_link( $term->slug, $attribute['name'] );
    					$attribute_string .= '<a href="' . $archive_link . '">'. $term->name . '</a>';
    				}
    			}
    		}
    		return '<p>'.$attribute_string.'</p>';
    	}

    Hi Rob Bertholf,

    You are a hero man.

    Your code works perfect for me.

    Thanks dear.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Make the attributes links?’ is closed to new replies.