Home / Admin / Add vendor id and name to CSV commissions export
Duplicate Snippet

Embed Snippet on Your Site

Add vendor id and name to CSV commissions export

Add vendor id and name to CSV commissions export

Code Preview
php
<?php
if ( ! function_exists( 'wcv_add_vendor_id_col_data' ) ) {
	/**
	 * Add vendor id to CSV data
	 *
	 * @param array $row_data The row data.
	 * @param int   $vendor_id The vendor id.
	 */
	function wcv_add_vendor_id_col_data( $row_data, $vendor_id ) {
		if ( isset( $row_data['vendor_id'] ) ) {
			$row_data['vendor_id'] = $vendor_id;
		}
		if ( isset( $row_data['vendor_name'] ) ) {
			$row_data['vendor_name'] = WCV_Vendors::get_vendor_shop_name( $vendor_id );
		}
		return $row_data;
	}
	add_filter( 'wcvendors_sum_commissions_export_row_data', 'wcv_add_vendor_id_col_data', 10, 2 );
}
if ( ! function_exists( 'wcv_add_vendor_name_col' ) ) {
	/**
	 * Add vendor name column to export
	 *
	 * @param array $columns The columns.
	 */
	function wcv_add_vendor_name_col( $columns ) {
		if ( isset( $columns['vendor_id'] ) ) {
			unset( $columns['vendor_id'] );
			$columns = array_merge(
				array(
					'vendor_id'   => __( 'Vendor ID', 'wc-vendors' ),
					'vendor_name' => __( 'Vendor Name', 'wc-vendors' ),
				),
				$columns
			);
		}
		return $columns;
	}
	add_filter( 'wcv_commissions_sum_export_columns', 'wcv_add_vendor_name_col', 10, 1 );
}

Comments

Add a Comment