Change Vendor Orders CSV Output

This snippet will give you the ability to modify the CSV download for your vendors. I did this for my site in order to enable my vendors to upload the CSV into the GoShippo shipping service. Since vendor-level integration with shipping services doesn’t seem to be possible, this at least enables vendors to upload the CSV in the necessary format to purchase and print paid shipping labels in bulk.

So, this snippet unsets various columns that were not necessary, including the column that displays the full shipping address in one line, since Shippo can’t recognize it. It then adds new columns for all the separate parts of the shipping address so that it works. I also take the opportunity to rename some things here as well.

Note: I’ve also tried to add order weight calculation and output to this csv, but have so far been unsuccessful in getting it to work.

As always, this is either added to your Child Theme’s functions.php file, or consider using the My Custom Functions Pro plugin to manage and organize all your snippets.

// Column headers unset and rename
add_filter( 'wcmp_vendor_order_generate_csv_headers', 'rename_column_headers' );
function rename_column_headers( $header ) {
    unset($header['shipping_address']);
    unset($header['time_of_purchase']);
    unset($header['vendor_name']);
    unset($header['commission_share']);
    unset($header['payment_system']);
    unset($header['buyer_email']);
    unset($header['billing_address']);
    $header['order'] = __('Order #', 'dc-woocommerce-multi-vendor' );
    $header['date_of_purchase'] = __('Date', 'dc-woocommerce-multi-vendor' );
    $header['product'] = __('Items', 'dc-woocommerce-multi-vendor' );
    $header['qty'] = __('Quantities', 'dc-woocommerce-multi-vendor' );
    $header['discount_used'] = __('Discount', 'dc-woocommerce-multi-vendor' );
    $header['shipping'] = __('Shipping Charge', 'dc-woocommerce-multi-vendor' );
    $header['buyer_contact'] = __('Phone', 'dc-woocommerce-multi-vendor' );
    $header['address_1'] = __('Shipping Address 1', 'dc-woocommerce-multi-vendor');
    $header['address_2'] = __('Shipping Address 2', 'dc-woocommerce-multi-vendor');
    $header['city'] = __('Shipping City', 'dc-woocommerce-multi-vendor');
    $header['state'] = __('Shipping State', 'dc-woocommerce-multi-vendor');
    $header['postcode'] = __('Shipping Postcode', 'dc-woocommerce-multi-vendor');
    $header['country'] = __('Shipping Country', 'dc-woocommerce-multi-vendor');

    return $header;
}

// Add new content
add_filter( 'wcmp_vendor_order_generate_csv_data', 'add_shipping_column_data', 10, 3 );
function add_shipping_column_data( $data ) {
    $data['address_1'] = $order->get_shipping_address_1();
    $data['address_2'] = $order->get_shipping_address_2();
    $data['city'] = $order->get_shipping_city();
    $data['state'] = $order->get_shipping_state();
    $data['postcode'] = $order->get_shipping_postcode();
    $data['country'] = $order->get_shipping_country();

    return $data;
}

Is this no longer relevant or not working? Please let us know in the comments!

Comments on this post

Your email address will not be published. Required fields are marked *