Enable Shortcode usage in WooCommerce WC_Product get_description() method

Viewed 242
1 Answers

You need simply to embed the product descition in WordPress do_shortcode() function like:

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>' . do_shortcode( $description ) . '
        </p>';
    }
    return $item_name;
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

Related