• Resolved zefyr

    (@zefyr)


    Hello, I use Orders CSV export, how can I send/load data from this order custom fields?

    I use this for custom csv columns

    function wc_csv_export_order_line_item_id($line_item, $item, $product) { 
      $line_item['sku'] = substr($product->get_sku(), 0, 4);
      $line_item['sku_full'] = $product->get_sku();
      $line_item['item_price'] = $product->get_price();
      return $line_item;
    }
    add_filter('wc_customer_order_csv_export_order_line_item', 'wc_csv_export_order_line_item_id', 10, 3);
    

    Or this for order fields:

    function wc_csv_export_modify_row_data( $order_data, $order, $csv_generator ) {
            global $product, $tax, $woocoommerce;      
    	$custom_data = array(
    		'column_1' => get_post_meta($order->id, '_billing_company_number', true),
    		'column_2' => get_post_meta($order->id, '_billing_vat_number', true),
                    'column_3' => get_post_meta($order->id, '_billing_vat_number_2', true)
    	);
     
    	$new_order_data = array();
    	if ( isset( $csv_generator->order_format ) && ( 'default_one_row_per_item' == $csv_generator->order_format || 'legacy_one_row_per_item' == $csv_generator->order_format ) ) {
    		foreach ( $order_data as $data ) {
    			$new_order_data[] = array_merge( (array) $data, $custom_data );
    		}
    	} else {
    		$new_order_data = array_merge( $order_data, $custom_data );
    	}
    	return $new_order_data;
    }
    add_filter( 'wc_customer_order_csv_export_order_row', 'wc_csv_export_modify_row_data', 10, 3 );
    

    Thank’s

    • This topic was modified 3 years, 6 months ago by zefyr.
    • This topic was modified 3 years, 6 months ago by zefyr.
Viewing 1 replies (of 1 total)
  • I solved it:

    'column_4' => get_post_meta($order->id, 'wc_order_field_2906', true),
    'column_5' => get_post_meta($order->id, 'wc_order_field_8140', true),
    'column_6' => get_post_meta($order->id, 'wc_order_field_9549', true)
    
Viewing 1 replies (of 1 total)
  • The topic ‘CSV EXPORT’ is closed to new replies.