• Resolved xqmano

    (@xqmano)


    I’m exporting all completed orders, including refunds, but I want the refunds to export as negative numbers. Is this at all possible?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author algol.plus

    (@algolplus)

    Hello

    Have you marked “Export refunds” in section “Filter by order” ?

    Thread Starter xqmano

    (@xqmano)

    Yes, I have, but I don’t entirely know why that doesn’t help.

    When I mark Export refunds, it returns empty rows in the export with order numbers I can’t find when I search for them under Orders in woocommerce.

    When I include Refunds under “Order statuses” I get the correct amounts, but in positive numbers.

    I use a translation of woocommerce, can that prevent it from working? It means, they have the tag “Refundert” rather than “Refunded”

    Plugin Author algol.plus

    (@algolplus)

    Hello

    When I mark Export refunds, it returns empty rows in the export with order numbers I can’t find when I search for them under Orders in woocommerce.

    Each time when you do refund (even partial) – Woocommerce creates child order (invisible in user interface).

    if you want to export negative numbers for main order – add this code to “Misc Settings” and tweak field list
    how to get field names – https://algolplus.com/plugins/documentation-order-export-woocommerce/
    thanks, Alex

    add_filter( "woe_fetch_order", function($row, $order ){
     $negative_cols = array("order_total","order_total_tax");//edit list
     if( $order->get_status() == "refunded") { 
         foreach($row as $k=>$v)
         if(in_array($k,$negative_cols))
            $row[$k] = - $v;
     }
     return $row;
    },10,2);
    Thread Starter xqmano

    (@xqmano)

    Hi again,

    This is the code I’ve pasted into misc. settings: I’ve replaced the field-list according to the link you provided. The product_value_qty is the only one I really need to appear in the negative, the order_total is just there to see if the problem is in the product-group. I’ve replaced get_status with “Refundert” as I’m using a norwegian version and that’s the status-text that’s used. But I’ve also tried with “refunded” as in your original code.

    Do you see any obvious mistakes I’ve made here?

    add_filter( "woe_fetch_order", function($row, $order ){
     $negative_cols = array("woe_get_order_value_order_total","woe_get_order_product_value_qty");
     if( $order->get_status() == "Refundert") { 
         foreach($row as $k=>$v)
         if(in_array($k,$negative_cols))
            $row[$k] = - $v;
     }
     return $row;
    },10,2);
    Plugin Author algol.plus

    (@algolplus)

    hi

    Could you try this code ?

    add_filter('woe_get_order_product_value_qty', function ($value, $order, $item, $product,$Item_meta) {
             if( $order->get_status() == "refunded") 
                      $value = -$value; 
    	return $value;
    }, 10, 5);
    Thread Starter xqmano

    (@xqmano)

    That seems to work exactly as I want it to! Thank you so much!

    Plugin Author algol.plus

    (@algolplus)

    you’re welcome

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Export refunds as negative number’ is closed to new replies.