3
votes

I want to display "product short description" in the "edit order" page below the product title in admin.

enter image description here


I am relatively new to WooCommerce and from what I have found I believe I should make use of the woocommerce_before_order_itemmeta action hook

Like:

add_action( 'woocommerce_before_order_itemmeta', 'short_discription', 10, 2 );
function short_discription(  ) {

}

Any help on how to adjust this further would be appreciated

1

1 Answers

3
votes

You are indeed using the correct hook, but you have access to 3 passed arguments (opposite 2). Namely: $item_id, $item & $product

Note: Because a variable product can only have 1 product short description, so all product variations would have exactly the same description. You can display the product variation description instead of product short description for variable products

So you get:

function action_woocommerce_before_order_itemmeta( $item_id, $item, $product ) {
    // Targeting line items type only
    if ( $item->get_type() !== 'line_item' ) return;
    
    // Variable 
    if ( $product->get_type() == 'variation' ) {
        // Get the variable product description
        $description = $product->get_description();     
    } else {
        // Get product short desciption
        $description = $product->get_short_description();       
    }
    
    // Isset & NOT empty
    if ( isset ( $description ) && ! empty( $description ) ) {
        echo $description;
    }
}
add_action( 'woocommerce_before_order_itemmeta', 'action_woocommerce_before_order_itemmeta', 10, 3 );

Result:

enter image description here