2017-10-20 73 views
1

在woocomerce中,如何獲得稅率費率用於訂購一種產品?和稅對於航運?獲取一個產品的訂單所用的稅率以及在WooCommerce中的運輸

+1

@LoicTheAztec請注意,問題是特定於*稅率* - 不是整個稅收細節。請不要編輯標題以使您的答案適合(但是,其他信息可能對某些人有用) – Cedric

+0

對不起,但我沒有嘗試使我的答案適合。我的實際答案是在第二個代碼片段中回答你的問題。 – LoicTheAztec

回答

1

你可以使用的項目(產品)的稅收數據,通過WC_Order_Item_Product對象和方法:

// 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 
} 

你也可以得到稅收數據(如運費)通過WC_Order_Item_Tax對象和方法

// 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 
} 
相關問題