• I’m trying to add a total billings column but I can’t get it to add correctly for each row of the spreadsheet since they are separate items

    How do you access which is the current item that a row is accessing?

    My current code is this:

    
    add_filter( "woe_fetch_order", function($row, $order){
    
    foreach( $order->get_items() as $order_item_id => $line ) {
        $row["net_billings"] = $row['products'][$order_item_id]['qty'] * 
        $row['products'][$order_item_id]['item_price'] - $row['order_refund'];
    }
    
    return $row;
    },10,2);
    
Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author algol.plus

    (@algolplus)

    “total billings column” — do you calculate the value the order ?
    Could you explain the formula?

    Thread Starter jlv4567

    (@jlv4567)

    Sorry it’s actually “net billings” but it should basically be the quantity of the item * the item_price – any amount refunded.

    So:
    (qty * item_price) - order_refund

    To give a net total that was billed. I can’t get it to show this net total for each row and item id though.

    Plugin Author algol.plus

    (@algolplus)

    hello

    please, open >Setup fields>Product Items and try field “Order Line Total (- Refund)”.
    thanks, Alex

    Thread Starter jlv4567

    (@jlv4567)

    Gah! That does it! I was told it didn’t exist so had to add it manually. Sorry!

    Thank you so much for the awesome help and response! You’re amazing!

    • This reply was modified 6 years, 4 months ago by jlv4567.
    Plugin Author algol.plus

    (@algolplus)

    if you still need custom field

    please follow to https://algolplus.freshdesk.com/support/solutions/articles/25000018287-add-calculated-field-for-product-

    and use code
    return $item->get_subtotal() - $order->get_qty_refunded_for_item( $item->get_id());

    Thread Starter jlv4567

    (@jlv4567)

    Awesome. Thank you!

    Thread Starter jlv4567

    (@jlv4567)

    Follow up question. How can I take the net_billings we just created and multiply it by a static field?

    I have a static field that’s a commission percentage that I’d like to multiply the net billings with. I can see that the static field is called “static_field_2”, but searching the forums didn’t reveal a way to access it.

    Here’s what I got with a hard coded .6, but I’d like to just grab that value from the static field.

    
    add_filter('woe_get_order_product_value_commission_amount', function ($value, $order, $item, $product, $item_meta) {
      return ($item->get_subtotal() - $order->get_qty_refunded_for_item( $item->get_id())) * .6;
    }, 10, 5);
    
    • This reply was modified 6 years, 4 months ago by jlv4567.
    • This reply was modified 6 years, 4 months ago by jlv4567.
    • This reply was modified 6 years, 4 months ago by jlv4567.
    Plugin Author algol.plus

    (@algolplus)

    hello

    yes, as nobody asked for these values.

    please, add this code at top of your function and press Preview – you will see fields.
    var_dump(WC_Order_Export_Engine::$current_job_settings['order_fields']); die();

    and use this field as multiplier ( replace “0” with correct index!) .

    WC_Order_Export_Engine::$current_job_settings['order_fields'][0]['value']

    Thread Starter jlv4567

    (@jlv4567)

    Hi, this little bit of code you gave above to use “Order Line Total (- Refund)” actually doesn’t seem to be getting the correct amount. I’ve got a line that has a item price of 500 and a refund of 505 and the “net billings” column we created shows as 500, but it should be -5. So it isn’t getting the right calculation.

    I tried to look in to it and this bit seems to always return 0 even if there is a refunded amount:

    
    $order->get_qty_refunded_for_item( $item->get_id())
    

    I tried switching to using get_qty_refunded_for_item but it still gets the 0.

    I think the problem may be that we are using the ‘Order Refund Amount’ under totals, and not the ‘Order Line Total Refunded’ under Products.

    The code for finding the static value works great though! Thank you for that!

    • This reply was modified 6 years, 4 months ago by jlv4567.
    • This reply was modified 6 years, 4 months ago by jlv4567.
    Plugin Author algol.plus

    (@algolplus)

    I think the problem may be that we are using the ‘Order Refund Amount’ under totals, and not the ‘Order Line Total Refunded’ under Products.

    yes, it’s a reason.
    you can try $order->get_total_refunded(), but it has no sense if you have 2+ products in the order.

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

The topic ‘Create new billings column’ is closed to new replies.