从 WooCommerce 订单应用的优惠券获取优惠券描述

Get coupon description From WooCommerce order applied coupons

我正在尝试在 WooCommerce 订单电子邮件中显示使用过的优惠券 + 添加说明。

显示优惠券的工作基于: Add Applied Coupon Code in Admin New Order Email Template - WooCommerce

我也试过这个:

$coupons = $order->get_items( 'coupon' );
  foreach ( $coupons as $item_id => $item ) {
    echo "<span class='coupon-name'><b>".$item['name']."</b></span>";
    $post = get_post( $item_id );
    echo "<p class='coupon-description'>".$post->post_excerpt."</p>";
  }
}

但是不起作用...有什么想法吗?

使用以下命令从“优惠券”订单项中获取优惠券说明:

// Loop through WC_Order_Item_Coupon Objects
foreach ( $order->get_items( 'coupon' ) as $item ) {
    // Get the WC_Coupon Object
    $coupon = new WC_Coupon($item->get_code());
    
    // Display coupon description
    echo "<p class='coupon-description'>".$coupon->get_description()."</p>";
}

相关:Get coupon data from WooCommerce orders