Last active
March 15, 2022 10:52
-
-
Save wtmujeebu/7f4f55d2b89a3c309cf03bb4a9f945fd to your computer and use it in GitHub Desktop.
Export WooCommerce Gift Card details with Order into separate column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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