Adding WooCommerce Order Notes to Attendees Export

Home Forums Ticket Products Event Tickets Plus Adding WooCommerce Order Notes to Attendees Export

  • This topic has 4 replies, 2 voices, and was last updated 9 years ago by Wayne Kessler.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1277256
    Wayne Kessler
    Participant

    I have successfully set up a site to export several WooCommerce order fields in the Attendees CSV Export. However, I’m also looking to get the Order Notes from each order into the export (it details the transaction and status info, like in the accompanying image). That’s proving to be a bit more of a challenge.

    I tried the following code, with several variations, but no luck in getting the notes to appear in the export:

    /* Tribe, adding user meta to the attendees csv export */
    function tribe_export_custom_set_up ( $event_id ) {
    
    	//Add Handler for Community Tickets to Prevent Notices in Exports
    	if ( ! is_admin() ) {
    		$screen_base = 'tribe_events_page_tickets-attendees';
    	} else {
    		$screen      = get_current_screen();
    		$screen_base = $screen->base;
    	}
    	$filter_name = "manage_{$screen_base}_columns";
    
    	add_filter( $filter_name, 'tribe_export_custom_add_columns', 100 );
    	add_filter( 'tribe_events_tickets_attendees_table_column', 'tribe_export_custom_populate_columns', 10, 3 );
    }
    add_action( 'tribe_events_tickets_generate_filtered_attendees_list', 'tribe_export_custom_set_up' );
    
    function tribe_export_custom_add_columns ( $columns ) {
    $columns['billing_first_name'] = 'Billing First Name';
    $columns['billing_last_name'] = 'Billing Last Name';
    $columns['billing_company'] = 'Billing Company';
    $columns['billing_address_1'] = 'Billing Address 1';
    $columns['billing_address_2'] = 'Billing Address 2';
    $columns['billing_city'] = 'Billing City';
    $columns['billing_state'] = 'Billing State';
    $columns['billing_postcode'] = 'Billing Zip';
    $columns['billing_phone'] = 'Phone';
    $columns['billing_email'] = 'Email';
    
    $columns['shipping_first_name'] = 'Shipping First Name';
    $columns['shipping_last_name'] = 'Shipping Last Name';
    $columns['shipping_company'] = 'Shipping Company';
    $columns['shipping_address_1'] = 'Shipping Address 1';
    $columns['shipping_address_2'] = 'Shipping Address 2';
    $columns['shipping_city'] = 'Shipping City';
    $columns['shipping_state'] = 'Shipping State';
    $columns['shipping_postcode'] = 'Shipping Zip';
    
    $columns['order_comments'] = 'Order Comments';
    
    $columns['order_date'] = 'Order Date';
    $columns['order_notes'] = 'Order Notes';
    return $columns;
    }
    
    function tribe_export_custom_populate_columns ( $value, $item, $column ) {
     
    $order = new WC_Order( $item['order_id'] );
    
    $date = utf8_decode($order->order_date);
    
    $bfirst = utf8_decode($order->billing_first_name);
    $blast = utf8_decode($order->billing_last_name);
    $bcompany = utf8_decode($order->billing_company);
    $badd1 = utf8_decode($order->billing_address_1);
    $badd2 = utf8_decode($order->billing_address_2);
    $bcity = utf8_decode($order->billing_city);
    $bstate = utf8_decode($order->billing_state);
    $bzip = utf8_decode($order->billing_postcode);
    $phone = utf8_decode($order->billing_phone);
    $email = utf8_decode($order->billing_email);
    
    $sfirst = utf8_decode($order->shipping_first_name);
    $slast = utf8_decode($order->shipping_last_name);
    $scompany = utf8_decode($order->shipping_company);
    $sadd1 = utf8_decode($order->shipping_address_1);
    $sadd2 = utf8_decode($order->shipping_address_2);
    $scity = utf8_decode($order->shipping_city);
    $sstate = utf8_decode($order->shipping_state);
    $szip = utf8_decode($order->shipping_postcode);
    
    $custcomments = utf8_decode($order->order_comments);
    
    $notes = utf8_decode($order->get_customer_order_notes);
    
     
    if ( isset($order) ) {
     
        switch ($column) {  
    	
    	 case 'order_date':
                $value = $date;
            break;
    	
    	    case 'billing_first_name':
                $value = $bfirst;
            break;
    		
    		case 'billing_last_name':
                $value = $blast;
            break;
    		
    		case 'billing_company':
                $value = $bcompany;
            break;
    		
    		case 'billing_address_1':
                $value = $badd1;
            break;
    		
    		case 'billing_address_2':
                $value = $badd2;
            break;
    		
    		case 'billing_city':
                $value = $bcity;
            break;
    		
    		case 'billing_state':
                $value = $bstate;
            break;
    		
    		case 'billing_postcode':
                $value = $bzip;
            break;
    		
    		case 'billing_phone':
                $value = $phone;
            break;
    		
    		case 'billing_email':
                $value = $email;
            break;
    		
    		
    		case 'shipping_first_name':
                $value = $sfirst;
            break;
    		
    		case 'shipping_last_name':
                $value = $slast;
            break;
    		
    		case 'shipping_company':
                $value = $scompany;
            break;
    		
    		case 'shipping_address_1':
                $value = $sadd1;
            break;
    		
    		case 'shipping_address_2':
                $value = $sadd2;
            break;
    		
    		case 'billing_city':
                $value = $scity;
            break;
    		
    		case 'shipping_state':
                $value = $sstate;
            break;
    		
    		case 'shipping_postcode':
                $value = $szip;
            break;
    		
    		
    		case 'order_comments':
                $value = $custcomments;
            break;
    		
    		case 'get_customer_order_notes':
                $value = $notes;
            break;
    }
        } else {
            $value = '-';
        }
        return $value;
    }

    I believe that WooCommerce handles the Order Notes as a standard WordPress comment. Do you have any suggestions about what might work in getting this into the Attendees export?

    #1278368
    Trisha
    Member

    Hello, Wayne!

    Thank you for using The Events Calendar! I can help with this ?

    See if this helps: https://gist.github.com/vanbo/b10de09ad367275d2bff

    I was able to take the code somewhat ‘as-is’ and add it to your functions with success. Part of the key is removing the filter that excludes the comments from queries (Line 24 in the gist). You’ll also need to account for the fact that there is more than one note per order but this should get you started!

    Does this help answer your question? Let me know how it goes!

    Cheers,
    Trisha

    #1278548
    Wayne Kessler
    Participant

    Hi Trisha,

    Thanks for your help! This is helping a good bit. I have been able to get the comments to show up in the export. At this point, it looks like it is grabbing just one comment from each other (sometimes it’s the first, sometimes not).

    I realize that grabbing every single one may be a bit of a mess. But do you have any suggestions on perhaps adding multiple comments to the export? Maybe we limit it to the last 3 or 4?

    #1278947
    Trisha
    Member

    Hello, Wayne!

    I’m glad this worked out for you!

    I think the order notes it really depends on how much ‘noise’ you can tolerate in the spreadsheet but your idea sounds valid for sure!

    I’m going to close this conversation out, but as always, if you need anything else feel free to reach out! I’m happy to help 🙂

    Cheers,
    Trisha

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Adding WooCommerce Order Notes to Attendees Export’ is closed to new replies.