Support » Plugin: Advanced Orders Export For WooCommerce » Exporting WooCommerce Box Office Fields

  • Resolved karks88

    (@karks88)


    Does anyone have insight on getting WooCommerce Box Office fields to export?

    Each event registration sold with this plugin allows the user to buy multiple tickets and assign a first name, last name and email address to each person they’re registering. So one order can have multiple registrants.

    The plugin comes with its own export utility but does not include all of the WooCommerce order fields with it – just the info from the ticket. So I’m hoping to just combine everything here in one export if possible.

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

    (@algolplus)

    Hello

    I think it’s possible, but mentioned plugin is not free, so

    Could you create new ticket here , upload “WooCommerce Box Office” plugin and sample output file?

    thanks, Alex

    • This reply was modified 6 months ago by  algol.plus.
    karks88

    (@karks88)

    Thank you, Alex! I’ll send you a sample output.

    Plugin Author algol.plus

    (@algolplus)

    ok, I’ll reply tomorrow.
    it’s late here

    Plugin Author algol.plus

    (@algolplus)

    here is code for this plugin
    read comments in line 2 !

    class WOE_BoxOfficeFields_As_Products {
    	var $fields = array('First Name','Last Name','Email'); // modify names here!  Must match to Labels at tab "Ticket Fields"
    	
    	function __construct() {
    		add_filter('woe_get_order_product_fields', function ($fields) {
    			$fields['product_ticket_id'] = array( 'label' => 'Ticket Id', 'colname' => 'Ticket Id', 'checked' => 1 );
    			foreach($this->fields as $name) 
    				$fields['product_'.$name] = array( 'label' => $name, 'colname' => $name, 'checked' => 1 );
    			return $fields;
    		});
    
    		add_filter('woe_fetch_order_products',function ($products,$order,$labels, $format, $static_vals) {
    			$this->line_id = 1;
    			$results = array();
    		    $pos = 0;
    			foreach ( $order->get_items('line_item') as $item_id=>$item ) {
    				// seek for assigned tickets 
    			    $product_data = $products[$pos++]; // take already extracted data for product!
    				foreach($item["item_meta"] as $key=>$value) {
    					if(strpos($key,"_ticket_id_for_") !== false ) 
    						$this->add_ticket($results, is_array($value)?$value[0]:$value,$labels,$product_data);
    				}
    			}
    			return $results;
    		},10,5);
    	}// end __construct
    	
    	function add_ticket(&$results, $ticket_id,$labels,$product_data) {
    		$data = array( 'product_ticket_id'=>$ticket_id);
    		
    		$product_id = get_post_meta( $ticket_id, '_product', true );
    		if ( !$product_id ) 
    			return;
    			
    		$ticket_product = wc_get_product( $product_id );
    		$data['name'] = $ticket_product->get_title();
    		
    	  
    		foreach ( wc_box_office_get_product_ticket_fields( $product_id ) as $field_key => $field ) {
    			// Replace content placeholders with ticket fields.
    			$field_value = get_post_meta( $ticket_id, $field_key, true );
    			if ( is_array( $field_value ) ) {
    				$field_value = implode( ', ', $field_value );
    			}
    			$data[ 'product_'.$field['label'] ] =  $field_value;
    		}		
    	  
    		foreach ( $labels as $field => $label ) {
    			if ( $field == 'line_id' ) {
    				$row[ $field ] = $this->line_id++; 
    			} elseif ( isset( $data[$field]) ) { // boxoffice fields 
    				$row[ $field ] = $data[$field];
    			} elseif ( isset( $product_data[ $field ] ) ) {
    				$row[ $field ] = $product_data[ $field ];
    			} else
    				$row[ $field ] = '';
    		}
    		$results[] = $row;
    	}
    }		
    new WOE_BoxOfficeFields_As_Products();
    
    Plugin Author algol.plus

    (@algolplus)

    this code works for manually created tickets/orders

    class WOE_BoxOfficeFields_As_Products {
    	var $fields = array('First Name','Last Name','Email'); // modify names here!  Must match to Labels at tab "Ticket Fields"
    	
    	function __construct() {
    		add_filter('woe_get_order_product_fields', function ($fields) {
    			$fields['product_ticket_id'] = array( 'label' => 'Ticket Id', 'colname' => 'Ticket Id', 'checked' => 1 );
    			foreach($this->fields as $name) 
    				$fields['product_'.$name] = array( 'label' => $name, 'colname' => $name, 'checked' => 1 );
    			return $fields;
    		});
    
    		add_filter('woe_fetch_order_products',function ($products,$order,$labels, $format, $static_vals) {
    			$this->line_id = 1;
    			$results = array();
    		    $pos = 0;
    			foreach ( $order->get_items('line_item') as $item_id=>$item ) {
    				// seek for assigned tickets 
    			    $product_data = $products[$pos++]; // take already extracted data for product!
    			    $found_ticket_ids = false;
    				foreach($item["item_meta"] as $key=>$value) {
    					if(strpos($key,"_ticket_id_for_") !== false ) {
    						$this->add_client_ticket($results, is_array($value)?$value[0]:$value,$labels,$product_data);
    					    $found_ticket_ids = true;
    					}
    				}
    			    if( !$found_ticket_ids ) {
    					// try parse manual ticket!
    		  			$product   = $order->get_product_from_item( $item );
    
    					foreach($item["item_meta"] as $key=>$value) {
    						if(preg_match('/Ticket #(\d+)/', $key, $m) ) {
    							$this->add_manual_ticket($results, $order->id."-".$m[1], is_array($value)?$value[0]:$value,$labels,$product_data);
    						}
    					}
    				}
    			}
    			return $results;
    		},10,5);
    	}// end __construct
    
      	function add_manual_ticket(&$results, $ticket_id,$ticket_data,$labels,$product_data) {
    		$data = array( 'product_ticket_id'=>$ticket_id);
    	  	$lines = explode("| ", $ticket_data);
    	    foreach($lines as $line) {
    			$cells = explode(": ", trim($line) );
    		    $data[ 'product_'. trim($cells[0]) ] =  $cells[1];
    		}
    	    $this->add_ticket($results, $data,$labels,$product_data);
    	}
      
    	function add_client_ticket(&$results, $ticket_id,$labels,$product_data) {
    		$data = array( 'product_ticket_id'=>$ticket_id);
    		
    		$product_id = get_post_meta( $ticket_id, '_product', true );
    		if ( !$product_id ) 
    			return;
    			
    		$ticket_product = wc_get_product( $product_id );
    		//$data['name'] = $ticket_product->get_title();
    
    	    foreach ( wc_box_office_get_product_ticket_fields( $product_id ) as $field_key => $field ) {
    			// Replace content placeholders with ticket fields.
    			$field_value = get_post_meta( $ticket_id, $field_key, true );
    			if ( is_array( $field_value ) ) {
    				$field_value = implode( ', ', $field_value );
    			}
    			$data[ 'product_'.$field['label'] ] =  $field_value;
    		}		
    	  
    	    $this->add_ticket($results, $data,$labels,$product_data);
    	}
      
        function add_ticket(&$results, $data,$labels,$product_data) {
    		foreach ( $labels as $field => $label ) {
    			if ( $field == 'line_id' ) {
    				$row[ $field ] = $this->line_id++; 
    			} elseif ( isset( $data[$field]) ) { // boxoffice fields 
    				$row[ $field ] = $data[$field];
    			} elseif ( isset( $product_data[ $field ] ) ) {
    				$row[ $field ] = $product_data[ $field ];
    			} else
    				$row[ $field ] = '';
    		}
    		$results[] = $row;
    	}
    }		
    new WOE_BoxOfficeFields_As_Products();
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Exporting WooCommerce Box Office Fields’ is closed to new replies.