- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我只想从税率降低的项目中导出优惠券总计(您可以在下图中看到的总计)。
对于这些项目的总数,我也这样做。 A great answer helped me仅导出税率降低的订单项目的总数。为此,我使用以下代码:
// gets the total of the order items by tax class
function get_total_order_items_by_tax_class( $order_id, $tax_class = 'reduced-rate' ) {
$order = wc_get_order( $order_id );
// initializes the total of the order items
$total = 0;
foreach( $order->get_items() as $item_id => $order_item ) {
// if the product tax class is equal to "$tax_class"
if ( $tax_class == $order_item['tax_class'] ) {
// sum the total
$total += $order_item['total'];
}
}
return $total;
}
我尝试了类似的东西并添加了以下行(
found here ):
$order->get_discount_total();
到片段。但这会导出每个税种的每个项目的全部折扣。
foreach( $order->get_coupon_codes() as $coupon_code ) {
// Get the WC_Coupon object
$coupon = new WC_Coupon($coupon_code);
$discount_type = $coupon->get_discount_type(); // Get coupon discount type
$coupon_amount = $coupon->get_amount(); // Get coupon amount
}
但这也是整个订单的折扣。
$order
仅包含优惠券总额和优惠券税。不是每个订单项。而且似乎
$order_item
不包含任何折扣。只有东西行
WC_Coupon_Data_Store_CPT
.
最佳答案
尝试以下操作以按税种获取订单商品折扣金额:
// Get order items discount amount excl. taxes by tax class
function get_order_items_discount_total_by_tax_class( $order_id, $tax_class = 'reduced-rate' ) {
$order = wc_get_order( $order_id );
$discount = 0; // Initializing;
foreach( $order->get_items() as $item ) {
// if the product tax class is equal to "$tax_class"
if ( $tax_class == $item['tax_class'] ) {
$discount += $item->get_subtotal() - $item->get_total(); // Excluding taxes
}
}
return $discount;
}
它应该工作。
关于php - WooCommerce:仅针对特定税种的商品获取折扣总额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66447543/
假设我有 15 个商店,每个商店有 4 种产品和自定义价格: 每个商店不会拥有全部 4 种产品,但只能有 2 种、3 种、4 种甚至 1 种。 价格相似,但根据每个商店定制。所有商店的价格每 2-3
我这辈子似乎无法获得我想要的结构并使其正常运行,所以我一怒之下来找你们。 设置:我有一个名为 Futures_Contracts 的目录,里面有大约 30 个文件夹,全部以标的 Assets 命名,最
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题吗? 更新问题,以便 editing this post 提供事实和引用来回答它. 关闭 9 年前。 Improve
所以我已经使用 Smalltalk 大约 6 个月了(Squeak 和 Pharo),主要是做数据分析,我即将开始我的第一个 Seaside 应用程序。所以我对所有 Smalltalkers 的问题是
我选择的选项对象如下所示: { 3 : 'c', 5 : 'a', 6 : 'b', ... } 我的重复看起来像这样: {{v}} 我想按值 (v) 排序,但据我所知
什么是最好的方法(使用的算法/数据结构)来获得在购物网站上订购的前 k 项商品,相关信息在其 n 个服务器中的每一个的日志中? 我正在考虑一种方法,该方法涉及维护一个固定大小的双向链表 k 每个节点都
我正在尝试编写一个模式来验证以下 XML: AK47 The USSR's chief export back in the day, and the guer
我们正在尝试将 Android Market 集成到我们的服务中,我们需要验证用户确实是特定应用程序的所有者,我们需要自动检索该特定应用程序的销售情况。 因此,我们一直在评估 Google Check
我们有一个代表客户购物记录的数组。例如,它是这样一个数组: custA, item1, custB, item1, custA, item2, custB, item3, custC, item1,
我是一名优秀的程序员,十分优秀!