Woocommerce info in CSV export?

Home Forums Ticket Products Event Tickets Plus Woocommerce info in CSV export?

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #1233690
    Christopher
    Participant

    Hi,

    Is there a way the attendee information of Woocommerce is included in the CSV export which you can get on the attendee page of an event? In the standard CSV export you only have name, email, ticket name and ID. On the order page you also have the address, but no option to export this data.

    Furthermore I have set some custom fields to the Woocommerce checkout page. I was able to include them into the detail view of a single order but now I’d like to have them included in the CSV export (and probably on the general order page) as well.

    I would appreciate a solution to this as I haven’t found anything that could help.

    Many thanks in advance!

    #1234702
    Brook
    Participant

    Howdy Christopher,

    I would love to assist as much as I can.

    This is certainly possible by using WP Filters. Checkout this example, which adds a column to the CSV export:

    https://slack-files.com/T0258N5TN-F2PKQ3FD3-b58b542827

    The function tribe_export_custom_add_columns () is adding column titles to the CSV export, while the function tribe_export_custom_populate_columns () is adding column data to each row. By modifying these two function you can add multiple columns, and populate them with any data you want. It will certainly take a bit of PHP knowhow, but assuming you have that or someone on staff who does, you should be able to get this accomplished no problem.

    Does that all make sense?

    Cheers!

    – Brook

    #1242801
    Christopher
    Participant

    Hi,

    thanks for your assistance!
    Am I right that this is for registered users? We only have tickets for unregistered users so there is no user_id.
    Is there any documentation about the functions so I can look which attribute we should check to get woocommerce data like “billing_postcode” and custom fields?

    I’m sorry if this is not understandable.

    #1242819
    Christopher
    Participant

    Just a quick update: I got it working! Everything’s quite fine now, except one little thing:

    Is it possible to exclude some columns? Things like the ticket id or security code are useless for our needs so it would be great if we could delete these columns from the csv export or if this is not possible to rearrange the order of the columns 🙂

    #1244375
    Lars
    Participant

    Hi I’m also trying to add the woocommerce info to my csv export but no luck yet. My users are also not registered, may I ask how did you got it working @Christopher? Any info would be greatly appreciated.

    #1244383
    Christopher
    Participant

    Hi Lars,

    just take the snippet you can find above and change the functions tribe_export_custom_add_columns and tribe_export_custom_populate_columns like this example:

    function tribe_export_custom_add_columns ( $columns ) {
    $columns['wc_first_name'] = 'First Name';
    $columns['wc_last_name'] = 'Last Name';
    $columns['wc_address'] = 'Address';
    return $columns;
    }
    function tribe_export_custom_populate_columns ( $value, $item, $column ) {
    
    $order = new WC_Order( $item['order_id'] );
    
    $firstname = utf8_decode($order->billing_first_name);
    $lastname = utf8_decode($order->billing_last_name);
    $address = utf8_decode($order->billing_address_1) . ' / ' . $order->billing_postcode . ' / ' . utf8_decode($order->billing_city); 
    
    if ( isset($order) ) {
    
    	switch ($column) {	
    	case 'wc_first_name':
    			$value = $firstname;
    		break;
    	case 'wc_last_name':
    			$value = $lastname;
    		break;
    	case 'wc_address':
    			$value = $address;
    		break;
    }
    	} else {
    		$value = '-';
    	}
    	return $value;
    }

    With this you get three additional columns in which the data of each attendee is included (only if the attendee has this data supplied).
    Does this help?

    #1244401
    Lars
    Participant

    Yes thank you @Christopher! Hadn’t thought about using a switch.. Great idea.

    #1245325
    Brook
    Participant

    That is beautiful code Cristopher. Thank you for sharing it.

    Is it possible to exclude some columns? Things like the ticket id or security code are useless for our needs so it would be great if we could delete these columns from the csv export or if this is not possible to rearrange the order of the columns ?

    That is definitely possible. Within the function tribe_export_custom_add_columns() you are adding columns to an array. But, you can also remove existing columns from that array. Inside the array there is a column with the key “security that you should be able to unset():

    unset( $columns['security'] );

    Just insert that code before the return function and the column will disappear. Do this with any columns you don’t want.

    Cheers!

    – Brook

    #1246119
    Christopher
    Participant

    Hey,

    Thanks!
    That is exactly what I nedd.
    Just one little thing: Is there a list of those keys? I’ve been searching for it but I haven’t been successful.

    Many thanks in advance and best regards
    Christopher

    #1246736
    Brook
    Participant

    Howdy Cristopher,

    The list of keys will depend on your system and which plugins you have installed. Instead of running unset() you could run var_dump($columns); and it will output a list. Or, of course you could use a debugger like x-debug. Whatever is easiest for you.

    Thanks for getting back!

    Cheers!

    – Brook

    #1248238
    Christopher
    Participant

    Hey Brook,

    Thanks for your reply and hints, I got it working although not all of the columns could be removed, but that’s fine.

    Best regards and many thanks
    Christopher

    #1248915
    Brook
    Participant

    It was my pleasure to help. I’m happy to hear you were able to add what you wanted. I’m puzzled that not all of the columns could be removed, though there are some columns I’ve not tried removing myself. Perhaps the default WordPress ones were giving you difficulty? Or something else was adding them after you removed them? Whatever the case it sounds like your happy with it for now. Just let us know if you ever need anything else. Cheers!

    – Brook

    #1259986
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 13 posts - 1 through 13 (of 13 total)
  • The topic ‘Woocommerce info in CSV export?’ is closed to new replies.