// Get the instance of the WC_Order Object from the $order_id variable
$order = wc_get_order( $order_id );
$product_names = array(); // Initializing
// Loop through order items
foreach( $order->get_items() as $item ) {
// check if a product is in specific category
if ( has_term( 'ebook', 'product_cat', $item['product_id'] ) )
{
$product_names[] = '"Ebook"';
}
elseif ( has_term( 'ticket', 'product_cat', $item['product_id'] ) )
{
$product_names[] = '"Ticket"';
}
else
{
$product_names[] = '"Others"';
}
}
$product_names = array_unique( $product_names );
echo sprintf( '<p>%s %s %s <strong>%s</strong> %s</p><br>',
_n( "Your", "Yours", sizeof( $product_names ), "woocommerce-bookings" ),
implode( ', ', $product_names ),
__("will be sent to", "woocommerce-bookings"),
$order->get_billing_email(),
__("as soon as the payment is received.", "woocommerce-bookings")
);
测试和工作