Home / Admin / Add order status to the commissions table export
Duplicate Snippet

Embed Snippet on Your Site

Add order status to the commissions table export

Code Preview
php
<?php
/**
 * Add order status to the commissions table export 
 */
function wcv_commission_export_columns( $columns ){
	$columns['order_status'] = __('Order Status','wc-vendors' );
	return $columns; 
} 
add_filter( 'wcv_commissions_export_columns', 'wcv_commission_export_columns', 1 );
/**
 * Add the order status column data to the csv export row
 */
function wcv_commission_column_data( $row, $commission ){
	$exporter = new WCV_Commissions_CSV_Export();
	$row = array();
	foreach ( $exporter->get_column_names() as $column_id => $column_name ) {
		switch ( $column_id ) {
			case 'vendor_id':
				$value = WCV_Vendors::get_vendor_shop_name( $commission->vendor_id );
				break;
			case 'totals':
				$totals = ( wc_tax_enabled() ) ? $commission->total_due + $commission->total_shipping + $commission->tax : $commission->total_due + $commission->total_shipping;
				$value  = wc_format_localized_price( $totals );
				break;
			case 'order_id':
				$order = wc_get_order( $commission->order_id );
				$value = ( $order ) ? $order->get_order_number() : $commission->order_id;
				break;
			case 'product_id':
				$parent          = get_post_ancestors( $commission->product_id );
				$product_id      = $parent ? $parent[0] : $commission->product_id;
				$wcv_total_sales = get_post_meta( $product_id, 'total_sales', true );
				if ( ! get_post_status( $product_id ) ) {
					$product_id = WCV_Vendors::find_parent_id_from_order( $commission->order_id, $product_id );
				}
				$value = get_the_title( $product_id ) . '(' . $wcv_total_sales . ')';
				break;
			case 'shipped': 
				$order = wc_get_order( $commission->order_id );
				if ( $order ){ 
					$shipped = get_post_meta( $order->get_id(), 'wc_pv_shipped', true ); 
					$value = ! empty( $shipped ) && in_array( $commission->vendor_id, $shipped ) ? __( 'Yes', 'wc-vendors' ) : __( 'No', 'wc-vendors'); 
				} else { 
					$value = '-';
				}
				break; 
			case 'order_status':
				$order = wc_get_order( $commission->order_id );
				$value = ( $order ) ? wc_get_order_status_name( $order->get_status() ) : $commission->order_id;
				break;
			default:
				$value = $commission->$column_id;
		}
		$row[ $column_id ] = $value;
	}
	return $row;
}
add_filter( 'wcv_commissions_export_row_data', 'wcv_commission_column_data', 10, 2 );

Comments

Add a Comment