WooCommerce TM Extra Product Options
You should EDIT and TWEAK code! See below how to get “Element id”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
// one column for each option class WOE_TM_extra__options_fields { // EDIT list here, use pair 'Export Label'=>['TM Field label', 'TM Field label 2', 'TM Field label N'] var $tm_fields = array( 'Age' =>['Age','Child Age','Children Age'], // 3 fields will be exported as "Age" 'Gender'=>['Gender'], 'Label1'=>['Front Label'], ); function __construct() { add_filter('woe_get_order_product_fields',array($this,'add_product_fields') ); add_filter('woe_get_order_product_item_meta', array($this,'fill_tm_fields') ); } function add_product_fields($fields) { foreach($this->tm_fields as $name=>$names) { $fields['tm_field_'.$name] = array('label'=>$name,'colname'=>$name,'checked'=>1); } return $fields; } //TWEAK output for each field function format_line($tm_field) { return $tm_field['value']; // can use $tm_field['name'], $tm_field['price'] , $tm_field['quantity'] } function fill_tm_fields($item_meta) { // Gather TM values to array $product_fields = array(); $product_fields[] = array(); //Cart Fees if( isset($item_meta["_tmcartfee_data"]) AND is_array($tmfields = maybe_unserialize($item_meta["_tmcartfee_data"][0])) ) { foreach($tmfields[0] as $tm_field) { $element_id = $tm_field['name']; if( !isset($product_fields[$element_id]) ) $product_fields[$element_id] = array(); $product_fields[$element_id][] = $this->format_line($tm_field); } } //Cart Items if( isset($item_meta["_tmcartepo_data"]) AND is_array($tmfields = maybe_unserialize($item_meta["_tmcartepo_data"][0])) ) { foreach($tmfields as $tm_field) { $element_id = $tm_field['name']; if( !isset($product_fields[$element_id]) ) $product_fields[$element_id] = array(); $product_fields[$element_id][] = $this->format_line($tm_field); } } //make list foreach($product_fields as $element_id=>$values) $product_fields[ $element_id ] = join("\n", $values); // add to item meta foreach($this->tm_fields as $name=>$element_ids) { //gather all keys $vals = array( ); foreach($element_ids as $element_id) { if( isset($product_fields[$element_id])) $vals[] = trim($product_fields[$element_id]); } // it must be array ! $item_meta['tm_field_'.$name] = array( join("\n", $vals) ); } return $item_meta; } } new WOE_TM_extra__options_fields(); |