UPDATE COMPATIBILITY for WooCommerce version 3+
Since WooCommerce 3, get_variation_description() now deprecated and replaced by the WC_Product get_description() method.
To get a description of the product description parameter in the basket (condition for the type of filtration product), you have 2 possibilities (maybe even more ...):
- Display variation descriptions using
woocommerce_cart_item_name , without editing any template. - Displays the description of the variation using the cart.php template.
In both cases, you do not need to use the foreach in the code, as mentioned earlier, because it already exists. Thus, the code will be more compact.
Case 1 - using woocommerce_cart_item_name :
add_filter( 'woocommerce_cart_item_name', 'cart_variation_description', 20, 3); function cart_variation_description( $name, $cart_item, $cart_item_key ) { // Get the corresponding WC_Product $product_item = $cart_item['data']; if(!empty($product_item) && $product_item->is_type( 'variation' ) ) { // WC 3+ compatibility $descrition = version_compare( WC_VERSION, '3.0', '<' ) ? $product_item->get_variation_description() : $product_item->get_description(); $result = __( 'Description: ', 'woocommerce' ) . $descrition; return $name . '<br>' . $result; } else return $name; }
In this case, the description is displayed only between the header values ββand the attribute values.
This code is in the function.php file of your active child theme (or theme), as well as in any plug-in file.
Case 2 Using the cart/cart.php template ( Update as per your comment).
You can choose where you want to display this description (2 options):
- After the name
- After the header values ββand variations.
Thus, you insert this code into the cart.php template around line 86 or 90 depending on your choice:
// Get the WC_Product $product_item = $cart_item['data']; if( ! empty( $product_item ) && $product_item->is_type( 'variation' ) ) { // WC 3+ compatibility $description = version_compare( WC_VERSION, '3.0', '<' ) ? $product_item->get_variation_description() : $product_item->get_description(); if( ! empty( $description ) ) { // '<br>'. could be added optionally if needed echo __( 'Description: ', 'woocommerce' ) . $description;; } }
All code is tested and fully functional.