Skip to content

Instantly share code, notes, and snippets.

@wtmujeebu
Last active March 15, 2022 10:52
Show Gist options
  • Save wtmujeebu/7f4f55d2b89a3c309cf03bb4a9f945fd to your computer and use it in GitHub Desktop.
Save wtmujeebu/7f4f55d2b89a3c309cf03bb4a9f945fd to your computer and use it in GitHub Desktop.
Export WooCommerce Gift Card details with Order into separate column
<?php // Do not copy this line
// Alter CSV header
add_filter('hf_alter_csv_header', 'hf_alter_order_csv_header', 10, 2);
function hf_alter_order_csv_header($export_columns, $max_line_items) {
$gift_card_details = array('gift_card', 'gift_card_amount');
array_splice($export_columns, 14, 0, $gift_card_details);
return $export_columns;
}
// Alter CSV data
add_filter('hf_alter_csv_order_data', 'hf_alter_csv_order_data', 10, 2);
function hf_alter_csv_order_data($order_export_data, $order_data_filter_args) {
$gift_card = '';
$gift_card_amount = '';
$order = wc_get_order($order_export_data['order_id']);
foreach ($order->get_items('gift_card') as $item_id => $item) {
$name = $item->get_name();
$gift_card .= html_entity_decode($name, ENT_NOQUOTES, 'UTF-8');
$gift_card_amount .= wc_format_decimal($item->get_amount(), 2);
}
$gift_card_details = array($gift_card, $gift_card_amount);
array_splice($order_export_data, 14, 0, $gift_card_details);
return $order_export_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment