- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我目前正在自定义客户在我的网站上购买后收到的电子邮件(客户处理订单、客户完成订单等)。我已将电子邮件文件夹从 Woocommerce 复制到我的子主题。
我正在做的是使用我自己的模板,然后使用 Woocommerce 类/API/函数来引入客户订单的相关详细信息。
到目前为止,我已经设法添加了以下信息:
我主要通过使用变量函数/类 $order (I.E id; ?>, billing_first_name; ?>) 来完成此操作
我的问题是我未能成功显示产品/商品(个人)价格。我已经查看并搜索了执行此操作的所有方法,但到目前为止我尝试的一切都失败了。
我在打印小计、运输、付款方式和总计(总成本)时也遇到了问题。也许我的做法不对?
这些是我用来尝试指导我的链接
How to get WooCommerce order details
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;
引用:Get Order items and WC_Order_Item_Product in Woocommerce 3
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
关于php - 在 Woocommerce 电子邮件中获取一些订单和订单项目数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51748956/
driver.get("https://www.yahoo.com/"); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS)
原始 DataFrame 只有 1 列元组。我想添加一列,其中包含每个元组中的项目数(长度)。 ITEMS 0 (EGG, WATER, TOMATOE) 1 (MILK
我有一个包含这些部分的 ListView。当有一个部分时,它就会取代另一个部分。也就是说,如果 ListView 项目计数为 30,则该部分将取代第一段,结果显示只有 29 点。 这里有一张图,很清楚
这个问题在这里已经有了答案: parsing nested parentheses in python, grab content by level (4 个答案) 关闭 4 年前。 我想提取与 a
我决定使用 Gwan 的 KV 存储来代替 Redis NoSQL 数据库。我在手册中看到,kv 支持文件 IO 的持久标志,以在重新启动之间保留我猜的数据。它使用回调recfn,但是这个函数究竟如何
我现在正在学习 swift。我在我的 swift 代码中使用了 ANetworking (Obj C 中的库)。我已经成功返回解析后的 JSON。但是我想找到返回的 json 项目的数量。这是我到目前
我正在重复这样的 JSON 对象(嵌套)项目列表: {{specific}} 我想在页面顶部的每个项目对象中显示“特定”项目的数量(在 ng-repeat 范围之外)。我无
我目前有 8 个 UITabBar 项目,所有这些项目都可以在“更多” View 中进行编辑。我的问题是,允许的标签栏项目的绝对最大数量是多少? 我理解5是一次最多可见的;我正在寻找您能拥有的最长月经
如果我在 DynamoDB 中扫描或查询,则可以设置 Limit属性(property)。 DynamoDB documentation说如下: The maximum number of items
我想知道的是我们如何在 Angular js 中获取项目的 ng-repeat 计数。从下面的代码中,我想获得技能的数量,因为我想对其进行限制。如果 skill count > 5 将 skill 限
我在日志中收到此异常 - java.lang.IndexOutOfBoundsException: Invalid item position 0(0). Item count:0
我是一名优秀的程序员,十分优秀!