• Resolved yewbeng0104

    (@yewbeng0104)


    Hi,

    I would like to display Product Description at Checkout page, i found that the code below can help:

    ***************************************************************
    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;
    }

    ***************************************************************

    The code will display Product Description as shown at screenshot below:
    https://drive.google.com/file/d/14oWXrdpZN7AHvQeszHf_b549Qs2eg_fx/view?usp=sharing

    However, it look not very neat. Thus, may i ask, how can we modify the code, in order to move down the Product Description value below the title “Description:”?

    Hope can show the result like this:

    Description:
    1.Statement of Income and Expenses (Profit & Loss Statement);
    2.Balance Sheet;
    3.Schedule of Fixed Assets;
    4.Summary of Financial Information
    5.Form P

    ***************************************************************

    Thank you!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    Hi there ??

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers!

    @yewbeng0104 do you have a link for this to be viewed? There may be some CSS that can be written to make the description to drop to a new line.

    Thread Starter yewbeng0104

    (@yewbeng0104)

    Hi,

    Thank you for the replies!
    For your information, I copy the code above from this article:
    https://stackoverflow.com/questions/46732243/add-product-description-to-cart-items-in-woocommerce

    Thank you!

    Okay thanks, then you could try inspecting your site and see wha the Div is that wraps the description and use the following css:

    .DIVNAME{
       width: 100%;
       clear: both;
       display: block;
    }

    You will need to replace DIVNAME with the class of the div that wraps the description

    Thread Starter yewbeng0104

    (@yewbeng0104)

    Hi,
    Thank you for your guideline.

    I not very understand. But when i try other code, the “description title” and “description value” can be separate to two line. The mention code is look like this:

    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;”>
    ‘.$label.’: <br>’.$description.’
    </p>’;
    }
    return $item_name;
    }

    ===============================================

    However, the code above will merge all “description value” into same line… Thus we do not use it… The result look like this:

    Description:
    1.Statement of Income and Expenses (Profit & Loss Statement);2.Balance Sheet;3.Schedule of Fixed Assets;4.Summary of Financial Information5.Form P

    Thank you very much for the replies!

    With out seeing it displayed on the site I can’t suggest any further, sorry I haven’t been of much help.

    • This reply was modified 3 years, 9 months ago by Robin.
    Thread Starter yewbeng0104

    (@yewbeng0104)

    It is ok, thank you very much!

    Thread Starter yewbeng0104

    (@yewbeng0104)

    solved

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Product Description at Checkout Page’ is closed to new replies.