• Resolved databell96

    (@databell96)


    I’m trying to export a range of orders along with the tracking number used for shipping the orders. The data is coming from the official WooCommerce Tracking plugin and the meta key is ‘_wc_shipment_tracking_items’ and inside of the meta value is a variable called ‘tracking_number’ which stores the tracking number I need for my CSV export.

    So I go to the Set up Fields to Export area, Click the Add Field button under Shipping. I type in the ‘_wc_shipment_tracking_items’ in the Meta Key field and set it to String for the field format. I’ve also tried using ‘tracking_number’ as well.

    Ran a test export and the tracking number data did not appear. Just blank cells for the column.

    Is there something I did wrong for the data not to appear?

    The page I need help with: [log in to see the link]

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

    (@algolplus)

    Hello

    Please, follow to https://algolplus.freshdesk.com/support/solutions/articles/25000016635-add-calculated-field-for-order-

    Add meta key “tracking_numbers” and put following code to “Misc Settings”
    thanks, Alex

    add_filter('woe_get_order_value_tracking_numbers', function ($value, $order,$field) {
            if( class_exists("WC_Shipment_Tracking_Actions") ) {
                $st = WC_Shipment_Tracking_Actions::get_instance();
                $tracking_items = $st->get_tracking_items( $order->get_id() );
                $numbers = array();
                foreach($tracking_items  as $item)
                    $numbers[] = $item['tracking_number'];
                $value = join(", ", array_filter($numbers)) ;    
            }
            return $value;
        }
    }, 10, 3);
    Plugin Author algol.plus

    (@algolplus)

    if this code doesn’t work – please, share official WooCommerce Tracking plugin via helpdesk

    Thread Starter databell96

    (@databell96)

    You PHP code returned an error:

    The code you are trying to save produced a fatal error on line 12:syntax error, unexpected ‘}’, expecting ‘,’ or ‘)’

    So I remove an extra ‘}’ at the end and it exported. But nothing came out of it. Still blank. I’ll send you the plugin.

    Plugin Author algol.plus

    (@algolplus)

    my bad , use this code.
    it works, I shared some screenshots via helpdesk

    add_filter('woe_get_order_value_tracking_numbers', function ($value, $order,$field) {
            if( class_exists("WC_Shipment_Tracking_Actions") ) {
                $st = WC_Shipment_Tracking_Actions::get_instance();
                $tracking_items = $st->get_tracking_items( $order->get_id() );
                $numbers = array();
                foreach($tracking_items  as $item)
                    $numbers[] = $item['tracking_number'];
                $value = join(", ", array_filter($numbers)) ;    
            }
            return $value;
    }, 10, 3);
    • This reply was modified 3 years, 11 months ago by algol.plus.
    Plugin Author algol.plus

    (@algolplus)

    last code works ok.

    the customer set wrong filter, so exported orders don’t have tracking details.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Issues trying to incorporate Custom Meta Key in Export’ is closed to new replies.