使用订单信息编辑电子邮件模板。如果我想发送订单,Woocommerce 会抛出一个错误(由于某种原因它没有显示,只是一个错误)。如果删除$item->get_price();
它,一切正常。我在哪里犯错?
$order_id = $order->get_id(); // The order_id
// get an instance of the WC_Order object
$order = wc_get_order( $order_id );
// The loop to get the order items which are WC_Order_Item_Product objects since WC 3+
foreach( $order->get_items() as $item_id => $item ){
//Get the product ID
$product_id = $item->get_product_id();
//Get the variation ID
$product_id = $item->get_variation_id();
//Get the WC_Product object
$product = $item->get_product();
// The quantity
$product_count = $item->get_quantity();
$product_price = $item->get_price();
// The product name
$product_name = $item->get_name(); // … OR: $product->get_name();
//Get the product SKU (using WC_Product method)
$sku = $product->get_sku();
echo "<tr><td><p>".$product_name." ".$sku."</p></td>"."<td><p>".$product_count."</p></td>"."<td><p>".$product_price."</p></td>"."</tr>";
}
get_price 函数在商品上,而不是在订单商品上。必须使用
$product->get_price()