在 Woocommerce 电子邮件中获取一些订单和订单项目数据
Get some order and order items data in Woocommerce emails
我目前正在自定义客户在我的网站上购买后收到的电子邮件(客户处理订单、客户完成订单等)。我已将电子邮件文件夹从 Woocommerce 复制到我的子主题。
我正在做的是使用我自己的模板,然后使用 Woocommerce Classes/API's/Functions 引入客户订单的相关详细信息。
到目前为止,我已经设法添加了以下信息:
- 客户姓名
- 客户订单号
- 订购日期
- Shipping/Billing地址
- 产品项目名称
- 产品项目数量
我主要是通过使用变量 function/class $order (I.E id; ?>, billing_first_name; ?>)
我的问题是我未能成功显示产品/商品(个人)价格。我已经查看并搜索了执行此操作的所有方法,但到目前为止我尝试的一切都失败了。
我在打印小计、运输、付款方式和总计(总成本)时也遇到了问题。也许我的做法不对?
这些是我用来指导我的链接
https://businessbloomer.com/woocommerce-easily-get-product-info-title-sku-desc-product-object/
任何帮助都会很棒。这是我的代码...
<?php
foreach ($order->get_items() as $item_id => $item_data) {
$product = $item_data->get_product();
//PRODUCT NAME
$product_name = $product->get_name();
echo $product_name// THIS WORKS AND PRINTS CORRECTLY
//PRODUCT QUANTITY
$get_quantity = WC_Order_Item::get_quantity();
echo $get_quantity // THIS WORKS AND PRINTS CORRECTLY
//PRODUCT PRICE
$get_price = new WC_Order_Item_Fee::get_amount( $context );
echo $get_price // THIS DOES NOT WORK
// TRYING BELOW ALSO DOES NOT WORK ...
$getproduct = wc_get_product( $item['product_id'] );
$price = $getproduct->get_price();
//HOW WOULD I GET :
/** SUBTOTAL , SHIPPING , PAYMENT METHOD AND TOTAL **/
?>
您的代码中存在一些错误……
1) 订单商品数据:
// Loop though order line items
foreach ($order->get_items() as $item_id => $item ) {
// PRODUCT NAME
$product_name = $item->get_name();
echo $product_name
// PRODUCT QUANTITY
$quantity = $item->get_quantity();
echo $quantity;
// Get the WC_Product Object instance
$product = $item->get_product();
// PRODUCT PRICE
$product_price = $product->get_price();
echo $product_price;
// LINE ITEM SUBTOTAL (Non discounted)
$item_subtotal = $item->get_subtotal();
echo $item_subtotal;
// LINE ITEM SUBTOTAL TAX (Non discounted)
$item_subtotal_tax = $item->get_subtotal_tax();
echo $item_subtotal_tax;
// LINE ITEM TOTAL (discounted)
$item_total = $item->get_total();
echo $item_total;
// LINE ITEM TOTAL TAX (discounted)
$item_total_tax = $item->get_total_tax();
echo $item_total_tax;
endforeach;
参考:
2) 对于订单数据:
// PAYMENT METHOD:
$payment_method = $order->get_payment_method(); // The payment method slug
$payment_method_title = $order->get_payment_method(); // The payment method title
// SHIPPING METHOD:
$shipping_method = $order->get_shipping_method(); // The shipping method slug
// SHIPPING TOTALS:
$shipping_total = $order->get_shipping_total(); // The shipping total
$shipping_total_tax = $order->get_shipping_tax(); // The shipping total tax
// DISCOUNT TOTAL
$shipping_total = $order->get_total_discount(); // The discount total
// ORDER TOTALS
$total = $order->get_total(); // The order total
$total_tax = $order->get_total_tax(); // The order tax total
我目前正在自定义客户在我的网站上购买后收到的电子邮件(客户处理订单、客户完成订单等)。我已将电子邮件文件夹从 Woocommerce 复制到我的子主题。
我正在做的是使用我自己的模板,然后使用 Woocommerce Classes/API's/Functions 引入客户订单的相关详细信息。
到目前为止,我已经设法添加了以下信息:
- 客户姓名
- 客户订单号
- 订购日期
- Shipping/Billing地址
- 产品项目名称
- 产品项目数量
我主要是通过使用变量 function/class $order (I.E id; ?>, billing_first_name; ?>)
我的问题是我未能成功显示产品/商品(个人)价格。我已经查看并搜索了执行此操作的所有方法,但到目前为止我尝试的一切都失败了。
我在打印小计、运输、付款方式和总计(总成本)时也遇到了问题。也许我的做法不对?
这些是我用来指导我的链接
https://businessbloomer.com/woocommerce-easily-get-product-info-title-sku-desc-product-object/
任何帮助都会很棒。这是我的代码...
<?php
foreach ($order->get_items() as $item_id => $item_data) {
$product = $item_data->get_product();
//PRODUCT NAME
$product_name = $product->get_name();
echo $product_name// THIS WORKS AND PRINTS CORRECTLY
//PRODUCT QUANTITY
$get_quantity = WC_Order_Item::get_quantity();
echo $get_quantity // THIS WORKS AND PRINTS CORRECTLY
//PRODUCT PRICE
$get_price = new WC_Order_Item_Fee::get_amount( $context );
echo $get_price // THIS DOES NOT WORK
// TRYING BELOW ALSO DOES NOT WORK ...
$getproduct = wc_get_product( $item['product_id'] );
$price = $getproduct->get_price();
//HOW WOULD I GET :
/** SUBTOTAL , SHIPPING , PAYMENT METHOD AND TOTAL **/
?>
您的代码中存在一些错误……
1) 订单商品数据:
// Loop though order line items
foreach ($order->get_items() as $item_id => $item ) {
// PRODUCT NAME
$product_name = $item->get_name();
echo $product_name
// PRODUCT QUANTITY
$quantity = $item->get_quantity();
echo $quantity;
// Get the WC_Product Object instance
$product = $item->get_product();
// PRODUCT PRICE
$product_price = $product->get_price();
echo $product_price;
// LINE ITEM SUBTOTAL (Non discounted)
$item_subtotal = $item->get_subtotal();
echo $item_subtotal;
// LINE ITEM SUBTOTAL TAX (Non discounted)
$item_subtotal_tax = $item->get_subtotal_tax();
echo $item_subtotal_tax;
// LINE ITEM TOTAL (discounted)
$item_total = $item->get_total();
echo $item_total;
// LINE ITEM TOTAL TAX (discounted)
$item_total_tax = $item->get_total_tax();
echo $item_total_tax;
endforeach;
参考:
2) 对于订单数据:
// PAYMENT METHOD:
$payment_method = $order->get_payment_method(); // The payment method slug
$payment_method_title = $order->get_payment_method(); // The payment method title
// SHIPPING METHOD:
$shipping_method = $order->get_shipping_method(); // The shipping method slug
// SHIPPING TOTALS:
$shipping_total = $order->get_shipping_total(); // The shipping total
$shipping_total_tax = $order->get_shipping_tax(); // The shipping total tax
// DISCOUNT TOTAL
$shipping_total = $order->get_total_discount(); // The discount total
// ORDER TOTALS
$total = $order->get_total(); // The order total
$total_tax = $order->get_total_tax(); // The order tax total