从 WooCommerce 订单应用优惠券获取优惠券说明

Rub*_*bén 5 php wordpress email-notifications coupon woocommerce

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

显示优惠券的工作原理是: 在管理新订单电子邮件模板中添加应用的优惠券代码 - 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>";
  }
}
Run Code Online (Sandbox Code Playgroud)

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

Loi*_*tec 3

使用以下命令从“优惠券”订单商品中获取优惠券描述:

// 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>";
}
Run Code Online (Sandbox Code Playgroud)

相关:从 WooCommerce 订单获取优惠券数据