Il y a 2 façons de le faire (faire le travail pour les produits et variations de produit):
1) Avec la fonction faite sur commande accrochée dans woocommerce_get_item_data
crochet d'action (La meilleure façon):
add_filter('woocommerce_get_item_data', 'customizing_cart_item_data', 10, 2);
function customizing_cart_item_data($cart_data, $cart_item) {
$custom_items = array();
$label = __('Description', 'woocommerce');
// Get the product description
$description = $cart_item['data']->get_description();
// For product variations when description is empty
if($cart_item['data']->is_type('variation') && empty($description)){
// Get the parent variable product object
$product = wc_get_product($cart_item['data']->get_parent_id());
// Get the variable product description
$description = $product->get_description();
}
// If product or variation description exists we display it
if(! empty($description)){
$custom_items[] = array(
'key' => $label,
'display' => $description,
);
}
// Merging description and product variation attributes + values
if(! empty($cart_data)) $custom_items = array_merge($custom_items, $cart_data);
return $custom_items;
}
Code va dans le fichier function.php de votre thème enfant actif (ou le thème) ou encore dans un fichier de plug-in.
... ou ...
2) Avec la fonction personnalisée accroché dans woocommerce_cart_item_name
crochet de filtre:
add_filter('woocommerce_cart_item_name', 'customizing_cart_item_data', 10, 3);
function customizing_cart_item_data($item_name, $cart_item, $cart_item_key) {
// The label
$label = __('Description', 'woocommerce');
// Get the product description
$description = $cart_item['data']->get_description();
// For product variations when description is empty
if($cart_item['data']->is_type('variation') && empty($description)){
// Get the parent variable product object
$product = wc_get_product($cart_item['data']->get_parent_id());
// Get the variable product description
$description = $product->get_description();
}
if(! empty($description)){
$item_name .= '<p class="item-description" style="margin:12px 0 0;">
<strong>'.$label.'</strong>: <br>'.$description.'
</p>';
}
return $item_name;
}
Code va dans le fichier function.php de votre thème enfant actif (ou le thème) ou aussi dans n'importe quel fichier plugin.
Le code est testé sur Woocommerce 3+ et fonctionne.
Quelle version de WooCommerce utilisez-vous en ce moment? –
J'utilise la version 4.8.2 –
C'est la dernière version de Wordpress mais vous êtes probablement sur WooCommerce version 3.2 si vous avez mis à jour le plugin. –