Created
July 23, 2020 21:57
-
-
Save DavidAnderson684/4c9e4747232e097b99eba09d0caaf1f6 to your computer and use it in GitHub Desktop.
Add columns to spreadsheet download
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 | |
if (!defined('ABSPATH')) die('No direct access.'); | |
add_filter('wc_eu_vat_certify_message', function($msg) { return 'For the correct carrying out of VAT auditing regulations, please confirm your country of residence:'; }); | |
// Below: adding columns to the spreadsheet | |
// Make sure that the order meta field 'PayPal Transaction Fee' is fetched from the database when selecting data for the report. | |
add_filter('wc_eu_vat_compliance_report_meta_fields', 'my_wc_eu_vat_compliance_report_meta_fields', 10, 2); | |
function my_wc_eu_vat_compliance_report_meta_fields($fields, $print_as_csv) { | |
// Stripe Fee is old | |
return $print_as_csv ? $fields.", 'PayPal Transaction Fee', '_stripe_fee', 'Stripe Fee'" : $fields; | |
} | |
// Give the order meta field 'PayPal Transaction Fee' the (internal) key 'pp_fee' | |
add_filter('wc_eu_vat_compliance_get_report_results_store_key', 'my_wc_eu_vat_compliance_get_report_results_store_key', 10, 2); | |
function my_wc_eu_vat_compliance_get_report_results_store_key($store, $res) { | |
if ('PayPal Transaction Fee' == $res->meta_key) return 'pp_fee'; | |
if ('_stripe_fee' == $res->meta_key && !empty($res->meta_value)) return 'stripe_fee'; | |
if ('Stripe Fee' == $res->meta_key && !empty($res->meta_value)) return 'stripe_fee'; | |
return $store; | |
} | |
// Add a column header 'PayPal Fee' to the spreadsheet | |
add_filter('wc_eu_vat_compliance_csv_header_columns', 'my_wc_eu_vat_compliance_csv_header_columns'); | |
function my_wc_eu_vat_compliance_csv_header_columns($columns) { | |
$columns[] = 'PayPal Fee'; | |
$columns[] = 'Stripe Fee'; | |
return $columns; | |
} | |
// For the 'PayPal Fee' column, insert the value that we fetched earlier (pp_fee) | |
add_filter('wc_eu_vat_compliance_csv_data_entries', 'my_wc_eu_vat_compliance_csv_data_entries', 10, 3); | |
function my_wc_eu_vat_compliance_csv_data_entries($data, $order_id, $order) { | |
$data['PayPal Fee'] = isset($order['pp_fee']) ? $order['pp_fee'] : ''; | |
$data['Stripe Fee'] = isset($order['stripe_fee']) ? $order['stripe_fee'] : ''; | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment