You must put this code to functions.php ( active theme)
I have to add new hook, so this code requires beta version
//WooCommerce TM Extra Product Options
class WOE_add_extra_fields {
var $tm_fields = array('Bio','Age'); //adjust list here
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 $pos=>$name) {
$fields['tm_field_'.$pos] = array('label'=>$name,'colname'=>$name,'checked'=>1);
}
return $fields;
}
function fill_tm_fields($item_meta) {
//got valid array ?
if( isset($item_meta["_tmcartepo_data"]) AND is_array($tmfields = maybe_unserialize($item_meta["_tmcartepo_data"][0])) ) {
// gather TM values
$product_fields = array();
foreach($tmfields as $tm_field) {
$product_fields[ $tm_field['name'] ] = $tm_field['value'];
}
// add to item meta
foreach($this->tm_fields as $pos=>$name) {
// it must be array !
$item_meta['tm_field_'.$pos] = array( isset($product_fields[$name]) ? $product_fields[$name] : "" );
}
}
return $item_meta;
}
}
new WOE_add_extra_fields();
-
This reply was modified 7 years, 10 months ago by algol.plus.