在WooCommerce管理订单中显示“产品简短描述”。

3
我希望在管理页面的“编辑订单”页面中,在产品标题下方显示“产品简短描述”。

enter image description here


我是相对新手的WooCommerce用户,根据我的了解,我认为我应该使用woocommerce_before_order_itemmeta动作钩子。
例如:
add_action( 'woocommerce_before_order_itemmeta', 'short_discription', 10, 2 );
function short_discription(  ) {

}

任何进一步调整的帮助都将不胜感激。
1个回答

3

您确实使用了正确的钩子,但您可以访问到3个传递的参数(相反的是2)。分别是:$item_id$item$product

注意:由于可变产品只能有一个产品简短描述,因此所有产品变体都将具有完全相同的描述。对于可变产品,您可以显示产品变体描述而不是产品简短描述

所以您会得到:

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 );

结果:

这里输入图片描述



需要更多上下文才能提供更准确的翻译。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接