• Resolved asgard01

    (@asgard01)


    Hi!
    Would you like to help me to create order_line_shipping custom field? I want to count cost of shipping for each item in one order (such as order_line_tax). This looks like this: (order_line_total / order_subtotal) * order_shipping_amount, but I can’t find how to add field with this formula.

    I will be very grateful for any help!

    • This topic was modified 7 years, 11 months ago by asgard01.
Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author algol.plus

    (@algolplus)

    hi

    try this code

    add_filter('woe_get_order_product_fields', 'woe_add_product_fields');
    function woe_add_product_fields($fields) {
    	$fields['order_line_shipping'] = array('label'=>'Shipping Cost','colname'=>'Shipping Cost','checked'=>1);
    	return $fields;
    }
    add_filter('woe_get_order_product_value_order_line_shipping','woe_fill_order_line_shipping', 10, 4);
    function woe_fill_order_line_shipping($value, $order, $item, $product) {
    	return round(  $item['line_total']/ $order->get_subtotal() *  $order->order_shipping, 2 );
    }
    
    Thread Starter asgard01

    (@asgard01)

    Thank you!

    The column ‘Shipping Cost’ was added to the export table, but it’s empty. Could this be due to the fact that I’m using the plugin version 1.2.1 (I can’t update my wordpress 4.5.2 right now)?

    Plugin Author algol.plus

    (@algolplus)

    Woocommerce version ?

    Thread Starter asgard01

    (@asgard01)

    2.5.3

    Woocommerce version ?

    Plugin Author algol.plus

    (@algolplus)

    So you see “0.00” in this column, correct ?

    Could you add

    var_dump($item['line_total'],$order->get_subtotal(),$order->order_shipping); die();

    above
    return round( $item['line_total']/ $order->get_subtotal() * $order->order_shipping, 2 );

    press Preview and paste output here ?

    Thread Starter asgard01

    (@asgard01)

    No, this column is completely empty. I tried to add the code above, but nothing has changed.

    Sorry, I can’t paste all private information from the output, but here part with ‘Shipping Cost’.

    part of output

    • This reply was modified 7 years, 11 months ago by asgard01.
    Plugin Author algol.plus

    (@algolplus)

    ok, I see the reason, you use outdated version of my plugin.

    Can you replace

    add_filter('woe_get_order_product_value_order_line_shipping','woe_fill_order_line_shipping', 10, 4);

    with

    add_filter('woe_get_order_product_csv_value_order_line_shipping','woe_fill_order_line_shipping', 10, 4);
    add_filter('woe_get_order_product_xls_value_order_line_shipping','woe_fill_order_line_shipping', 10, 4);
    Thread Starter asgard01

    (@asgard01)

    Yeah! It’s work.
    You are awesome support! Thank you so much!

    Plugin Author algol.plus

    (@algolplus)

    you’re welcome

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘order_line_shipping custom field’ is closed to new replies.