Woocommerce Subscriptions
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 |
// add status and dates as new columns class WOE_Subscription_Fields_mod { function __construct() { add_filter('woe_get_order_fields', array($this,'add_order_fields') ); add_action('woe_order_export_started', array($this,'get_subscription_details') ); add_filter('woe_fetch_order_row', array($this,'fill_new_columns'), 10, 2); } function add_order_fields($fields) { $fields['sub_status'] = array('segment'=>'cart','label'=>'Sub. Status', 'colname'=>'Sub. Status', 'value'=>'','checked'=>1); $fields['sub_start_date'] = array('segment'=>'cart','label'=>'Sub. Start Date', 'colname'=>'Sub. Start Date', 'value'=>'','checked'=>1); $fields['sub_next_payment'] = array('segment'=>'cart','label'=>'Sub. Next Payment', 'colname'=>'Sub. Next Payment', 'value'=>'','checked'=>1); $fields['sub_last_order_date'] = array('segment'=>'cart','label'=>'Sub. Last Order Date', 'colname'=>'Sub. Last Order Date', 'value'=>'','checked'=>1); return $fields; } function get_subscription_details($order_id) { $this->sub = array(); if( WC_Order_Export_Data_Extractor::$object_type=='shop_order' ) { $subs = wcs_get_subscriptions_for_order($order_id, array('order_type'=>'any')); $subs = array_values($subs); if(!$subs) return $order_id; $sub = array_shift($subs); } elseif(WC_Order_Export_Data_Extractor::$object_type=='shop_subscription' ) { $sub = wcs_get_subscription($order_id); } else { return $order_id;// unknow type } $this->sub['status'] = $sub->get_status(); //$this->sub['start_date'] = $sub->get_date_to_display("start_date"); //was $this->sub['start_date'] = date_i18n( wc_date_format(), $sub->get_time( 'date_created', 'site' ) ); $this->sub['next_payment'] = $sub->get_time( 'next_payment_date', 'site' ) ? date_i18n( wc_date_format(), $sub->get_time( 'next_payment_date', 'site' ) ) : '-'; $this->sub['last_order_date'] = date_i18n( wc_date_format(), $sub->get_time( 'last_order_date_created', 'site' ) ); return $order_id; } // add new values to row function fill_new_columns($row,$order_id) { foreach($this->sub as $k=>$v) if(isset($row['sub_'.$k])) $row['sub_'.$k] = $v; return $row; } } new WOE_Subscription_Fields_mod(); |