WooCommerce Checkout Add-ons
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 |
// "Checkout Add-ons" plugin class WOE_Checkout_Addons_Mod { var $fields = array('Student Name','Student Grade Lavel','Teacher Name');// edit this line!! function __construct() { add_filter('woe_get_order_fields', array($this,'add_order_fields') ); add_action('woe_order_export_started', array($this,'get_fee_details') ); add_filter('woe_fetch_order_row', array($this,'fill_new_columns'), 10, 2); } function add_order_fields($fields) { foreach($this->fields as $pos=>$name) { $fields['fee_addon_'.$pos] = array('segment'=>'other','label'=>$name, 'colname'=>$name,'checked'=>1); } return $fields; } function get_fee_details($order_id) { $this->fee_data = array(); $order = new WC_Order($order_id); foreach($order->get_items("fee") as $item_id=>$item) { $pos = array_search($item['name'],$this->fields); if( $pos !== false) { $item_meta = $order->get_item_meta( $item_id ); $this->fee_data[$pos] = join(", ", $item_meta['_wc_checkout_add_on_value']); // many values? } } return $order_id; } // add new values to row function fill_new_columns($row,$order_id) { foreach($this->fields as $pos=>$name) { if(isset($row['fee_addon_'.$pos]) AND isset($this->fee_data[$pos]) ) $row['fee_addon_'.$pos] = $this->fee_data[$pos] ; } return $row; } } new WOE_Checkout_Addons_Mod(); |