Disable field rounding
-
Hi Alex,
In another topic I found the snippet below. The goal is to completely disable field rounding.
add_filter (‘woe_get_order_fields’, function ($ fields) {
unset ($ fields [“order_total_tax”] [“format”]);
return $ fields;Unfortunately, exports continue to round to 2 decimal places. Do you have any idea how to manipulate this?
Thank you in advance.
-
hi
please, open “Misc Settings” and turn off “Format numbers”.
thanks, AlexHi Alex,
This setting is not enabled.
To rule things out I created a test environment with a clean installation of WordPress, Woocommerce and Advanced Order Export For WooCommerce. Unfortunately the same result.
Matthijs
my bad, we round it π
please, delete the field and add it again using this way
– open Setup fields
– click Add Field
– use key “total_tax”-
This reply was modified 5 years, 3 months ago by
algol.plus.
Thank you for your message.
Then I still get 0.82. While I expect 0.824862. Which Field format should I select? Does the tab where I add the field matter?
Below some extra info:
WooCommerce order values:
Total: 9,165138
Tax: 0.824862Values after export:
Total: 9.17
Tax: 0.82Settings:
Prices entered including VAT: Yes
Tax rate: 9%
Price: β¬ 9.99Matthijs
I was wrong , I see key “_order_tax” in postmeta. please, try it.
That indeed seems to work, but in my case it concerns the following fields:
order_subtotal
order_shipping
order_total
order_total_tax
item_priceSorry for the confusion. I assumed there would be one adjustment for all fields.
I’m sorry, but
By default, the plugin should export taxes as WooCommerce shows them.
so we had to use wc_round_tax_total() function.No problem, but what should I do to make the other fields not rounded in the export?
If I’m not mistaken those fields are not in the postmeta like _order_tax.
I hope you can help. This is essential for proper processing in the accounting system.
hi
you can add this code to section “Misc Settings” and override all values
add_filter( "woe_fetch_order", function ($row, $order) { $row['order_subtotal'] = $order->get_subtotal(); $row['order_total_tax'] = $order->get_total_tax(); return $row; },10,2);$order is https://docs.woocommerce.com/wc-apidocs/class-WC_Order.html
I see. The filter works. Unfortunately, these WordPress $order functions again return rounded values. Is this something I have to fix myself?
Other question. Is there also a filter for the WC_Product class? I have tried the following but it doesn’t seem to go well:
add_filter (“woe_fetch_product”, function ($row, $product) {}
Thanks again for your time.
hello
Do you see non-rounded values in table wp_postmeta ? try use “Add Field” in this case.
we use a bit different hook for product
add_filter( 'woe_fetch_order_product', function($row, $order, $item, $product, $item_meta ){ $row['item_price'] = $order->get_item_total( $item, false, false ); return $row; },10,5);thanks, Alex
My mistake looks like the values are correct!
I try to do the same with the shipping costs. The following filter returns a rounded value. Looks like get_shipping_total() ignores the parameters. Do you have any idea how to fix that?
//export Shipping line as Products
add_filter(‘woe_fetch_order_products’, function ($products,$order,$labels, $format, $static_vals) {
$i = count ($products);
foreach ( $order->get_items(‘shipping’) as $item_id=>$item ) {
$row = array();
$i++;
$taxes = $item->get_total_tax();
foreach ( $labels as $field => $label ) {
if ( $field == ‘item_price’ ) {
$row[‘item_price’] = $order->get_shipping_total( $item, false, false );
}
}
$products[] = $row;
}
return $products;
}, 10, 5);Matthijs
get_shipping_total uses different parameters
https://woocommerce.github.io/code-reference/classes/WC-Abstract-Order.html#method_get_shipping_totalBut $item is https://woocommerce.github.io/code-reference/classes/WC-Order-Item-Shipping.html , so try $item->get_total(‘edit’)
-
This reply was modified 5 years, 3 months ago by
algol.plus.
-
This reply was modified 5 years, 3 months ago by
The topic ‘Disable field rounding’ is closed to new replies.