php - How to show product attribute name in cart page -


one of favorite members helgatheviking, gave me solution of previous question remove quantity field cart page specific product attribute . below function given her.

add_filter( 'woocommerce_cart_item_quantity', 'remove_cart_item_quantity', 10, 2 ); function remove_cart_item_quantity( $product_quantity, $cart_item_key ){     $cart_item = wc()->cart->cart_contents[ $cart_item_key ];     if( $cart_item['data']->is_type( 'variation' ) ){         $attributes = $cart_item['data']->get_attributes();         // var_dump( $attributes );         if( array_key_exists( 'color', $attributes ) ){             $product_quantity = '';         }     }     return $product_quantity; } 

now $product_quantity; return blank string.

is possible show name instead of blank. $product_quantity = ''; should replace ? if selected product has color green $product_quantity; should return green. example: $product_quantity = '$color'; how color string product attribute in cart.

i solve $_pname = wc()->cart->get_item_data( $cart_item ); can use $product_quantity = str_ireplace( 'choose quantity:', '',$_pname) ;

add_filter( 'woocommerce_cart_item_quantity', 'remove_cart_item_quantity', 10, 2 ); function remove_cart_item_quantity( $product_quantity, $cart_item_key ){     $cart_item = wc()->cart->cart_contents[ $cart_item_key ];     if( $cart_item['data']->is_type( 'variation' ) ){         $attributes = $cart_item['data']->get_attributes();         $_pname = wc()->cart->get_item_data( $cart_item );         if( array_key_exists( 'choose-quantity', $attributes ) ){             $product_quantity = str_ireplace( 'choose quantity:', '',$_pname) ;         }     }     return $product_quantity; } 

output: output cart.php


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -