bluvertigo
4/8/2015 - 4:27 PM

Aggiungere elemento al nome del prodotto nel carrello / Show WooCommerce Product Attributes on Cart Page - http://isabelcastillo.com/show-wo

Aggiungere elemento al nome del prodotto nel carrello / Show WooCommerce Product Attributes on Cart Page - http://isabelcastillo.com/show-woocommerce-product-attributes-on-cart-page

/**
* WooCommerce: show all product attributes listed below each item on Cart page
*/
function isa_woo_cart_attributes($cart_item, $cart_item_key){
   
    $item_data = $cart_item_key['data'];
    $attributes = $item_data->get_attributes();
       
       
    if ( ! $attributes ) {
        return $cart_item;
    }
       
    $out = $cart_item . '<br />';
      
    foreach ( $attributes as $attribute ) {
  
        if ( $attribute['is_taxonomy'] ) {
         
        // skip variations
            if ( $attribute['is_variation'] ) {
                continue;
            }
  
            // backwards compatibility for attributes which are registered as taxonomies
              
            $product_id = $item_data->id;
            $terms = wp_get_post_terms( $product_id, $attribute['name'], 'all' );
              
            // get the taxonomy
            $tax = $terms[0]->taxonomy;
              
            // get the tax object
            $tax_object = get_taxonomy($tax);
              
            // get tax label
            if ( isset ($tax_object->labels->name) ) {
                $tax_label = $tax_object->labels->name;
            } elseif ( isset( $tax_object->label ) ) {
                $tax_label = $tax_object->label;
            }
              
            foreach ( $terms as $term ) {
                $out .= $tax_label . ': ';
                $out .= $term->name . '<br />';
            }
             
        } else {
         
            // not a taxonomy 
             
            $out .= $attribute['name'] . ': ';
            $out .= $attribute['value'] . '<br />';
        }
    }
    echo $out;
}
   
add_filter( 'woocommerce_cart_item_name', isa_woo_cart_attributes, 10, 2 );