|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Show the product price in the Default - One Row per Item order export format |
| 4 | + * Adds a column for item price |
| 5 | + */ |
| 6 | + |
| 7 | + |
| 8 | +/** |
| 9 | + * Add the product price to the individual line item entry |
| 10 | + * |
| 11 | + * @param array $line_item the original line item data |
| 12 | + * @param array $item WC order item data |
| 13 | + * @param WC_Product $product the product |
| 14 | + * @return array updated line item data |
| 15 | + */ |
| 16 | +function sv_wc_csv_export_order_line_item_price( $line_item, $item, $product ) { |
| 17 | + |
| 18 | + $line_item['price'] = $product->get_price(); |
| 19 | + |
| 20 | + return $line_item; |
| 21 | +} |
| 22 | +add_filter( 'wc_customer_order_csv_export_order_line_item', 'sv_wc_csv_export_order_line_item_price', 10, 3 ); |
| 23 | + |
| 24 | + |
| 25 | +/** |
| 26 | + * Add `item_price` column to the Default - One Row per Item export format |
| 27 | + * |
| 28 | + * @param array $column_headers the original column headers |
| 29 | + * @param WC_Customer_Order_CSV_Export_Generator $csv_generator the generator instance |
| 30 | + * @return array the updated column headers |
| 31 | + */ |
| 32 | +function sv_wc_csv_export_modify_column_headers_item_price( $column_headers, $csv_generator ) { |
| 33 | + |
| 34 | + if ( 'default_one_row_per_item' === $csv_generator->order_format ) { |
| 35 | + |
| 36 | + $new_headers = array( |
| 37 | + 'item_price' => 'item_price', |
| 38 | + ); |
| 39 | + |
| 40 | + $column_headers = array_merge( $column_headers, $new_headers ); |
| 41 | + } |
| 42 | + |
| 43 | + return $column_headers; |
| 44 | +} |
| 45 | +add_filter( 'wc_customer_order_csv_export_order_headers', 'sv_wc_csv_export_modify_column_headers_item_price', 10, 2 ); |
| 46 | + |
| 47 | + |
| 48 | +/** |
| 49 | + * Add the item_price column data for the Default - One Row per Item format |
| 50 | + * |
| 51 | + * @param array $order_data the original order data |
| 52 | + * @param array $item the item for this row |
| 53 | + * @return array the updated order data |
| 54 | + */ |
| 55 | +function sv_wc_csv_export_order_row_one_row_per_item_price( $order_data, $item ) { |
| 56 | + |
| 57 | + $order_data['item_price'] = $item['price']; |
| 58 | + |
| 59 | + return $order_data; |
| 60 | +} |
| 61 | +add_filter( 'wc_customer_order_csv_export_order_row_one_row_per_item', 'sv_wc_csv_export_order_row_one_row_per_item_price', 10, 2 ); |
0 commit comments