In woocomerce, how to get the tax rate used in an order for one product ? And the tax rate For shipping ?
1条回答 默认 最新
- dsadsadsa1231 2017-10-20 18:05关注
You can get the tax data used for an item (product) through
WC_Order_Item_Product
object and methods:// Get the an occurrence of the WC_Order object (if needed, from a defined $order ID) $order = wc_get_order( $order_id ); // Iterating through WC_Order_Item_Product objects foreach( $order->get_items() as $item_id => $line_item ){ ## -- Get all protected data in an accessible array -- ## $item_data = $line_item->get_data(); // Get the Tax data in an array $item_tax_class = $item_data['tax_class']; $item_subtotal_tax = $item_data['subtotal_tax']; $item_total_tax = $item_data['total_tax']; $item_taxes_array = $item_data['taxes']; ## -- OR Use WC_Order_Item_Tax methods -- ## $item_tax_class = $line_item->get_tax_class(); // Tax class $item_subtotal_tax = $line_item->get_subtotal_tax(); // Line item name $item_total_tax = $line_item->get_total_tax(); // Tax rate code $item_taxes_array = $line_item->get_taxes(); // Tax detailed Array }
Also you can get Tax data (like shipping) through
WC_Order_Item_Tax
object and methods// Get the an occurrence of the WC_Order object (if needed, from a defined $order ID) $order = wc_get_order( $order_id ); // Iterating through WC_Order_Item_Tax objects foreach( $order->get_items( 'tax' ) as $item_id => $item_tax ){ ## -- Get all protected data in an accessible array -- ## $tax_data = $item_tax->get_data(); // Get the Tax data in an array $item_tax_rate_code = $tax_data['rate_code']; $item_tax_rate_id = $tax_data['rate_id']; $item_tax_label = $tax_data['label']; $item_tax_total = $tax_data['tax_total']; // Tax total amount $item_tax_shipping_total = $tax_data['shipping_tax_total']; // Tax shipping total ## -- OR Use WC_Order_Item_Tax methods -- ## $item_type = $item_tax->get_type(); // Line item type $item_name = $item_tax->get_name(); // Line item name $rate_code = $item_tax->get_rate_code(); // Tax rate code $tax_rate_label = $item_tax->get_label(); // Tax label $tax_rate_id = $item_tax->get_rate_id(); // Tax rate ID $compound = $item_tax->get_compound(); // Tax compound $tax_amount_total = $item_tax->get_tax_total(); // Tax rate total $tax_shipping_total = $item_tax->get_shipping_tax_total(); // Tax shipping total }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥50 有数据,怎么建立模型求影响全要素生产率的因素
- ¥50 有数据,怎么用matlab求全要素生产率
- ¥15 TI的insta-spin例程
- ¥15 完成下列问题完成下列问题
- ¥15 C#算法问题, 不知道怎么处理这个数据的转换
- ¥15 YoloV5 第三方库的版本对照问题
- ¥15 请完成下列相关问题!
- ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
- ¥15 求daily translation(DT)偏差订正方法的代码
- ¥15 js调用html页面需要隐藏某个按钮