我最近刚刚为Woocommerce创建了自定义电子邮件。除了一个问题,我有一切工作。在我带来/获得“产品形象”之前,我能够毫无问题地加载“产品价格”。
但是现在我得到了产品图片,我无法获得“产品价格”,订单也没有得到处理和完成。
这是我用来收集电子邮件中显示的所有信息的PHP代码。
<?php
foreach ($order->get_items() as $theitem_id => $theitem ) {
// PRODUCT NAME
$product_name = $theitem->get_name();
// PRODUCT QUANTITY
$quantity = $theitem->get_quantity();
// LINE ITEM SUBTOTAL (Non discounted)
$item_subtotal = $theitem->get_subtotal();
$item_subtotal = number_format( $item_subtotal, 2 );
// LINE ITEM TOTAL (discounted)
$item_total = $theitem->get_total();
$item_total = number_format( $item_total, 2 );
$product_id = $theitem['product_id'];
$product = wc_get_product( $product_id );
// PRODUCT IMAGE
$prodimage = $product->get_image( array( 200, 200 ) )
// PRODUCT PRICE
$product_price = $product->get_price();
?>
我确信我离这个权利不远,因为当我评论“产品价格”PHP代码然后一切正常(没有明显收集价格)
任何帮助都会很棒,非常感谢
自Woocommerce 3以来,产品ID错误(产品对象也是如此)...请尝试:
<?php
// Loop through order items
foreach ($order->get_items() as $item_id => $item ) {
// PRODUCT NAME
$product_name = $item->get_name();
// PRODUCT QUANTITY
$quantity = $item->get_quantity();
// LINE ITEM SUBTOTAL (Non discounted)
$item_subtotal = $item->get_subtotal();
$item_subtotal = number_format( $item_subtotal, 2 );
// LINE ITEM TOTAL (discounted)
$item_total = $item->get_total();
$item_total = number_format( $item_total, 2 );
// Get an instance of the product Object
$product = $item->get_product(); // <==== HERE
$product_id = $product->get_id(); // <==== and HERE
// PRODUCT IMAGE
$product_image = $product->get_image( array( 200, 200 ) );
// PRODUCT PRICE
$product_price = $product->get_price();
?>
它现在应该更好地工作。
相关:Get Order items and WC_Order_Item_Product in Woocommerce 3