Created
May 25, 2020 23:01
-
-
Save NickGreen/ba2a68c9953b2bfdfa157f7a3267eaf9 to your computer and use it in GitHub Desktop.
Add "recipient" to subscriptions export, for use with Gifting for WooCommerce Subscriptions
This file contains hidden or 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 | |
/** | |
* Add custom headers to the list of default headers exported in the CSV | |
* | |
* @param array $headers | |
* @return array | |
*/ | |
function my_custom_export_headers( $headers = array() ) { | |
return array_merge( $headers, array( | |
'_recipient_user' => 'Recipient', | |
) ); | |
} | |
add_filter( 'wcsie_export_headers', 'my_custom_export_headers', 10, 1 ); | |
/** | |
* Adds a custom meta value to the exported row | |
* | |
* @param string value | |
* @param WC_Subscription $subscription | |
* @param | |
* @return string | |
*/ | |
function my_custom_export_values( $value, $subscription, $header_key ) { | |
error_log( print_r( $subscription, true ) ); | |
if ( '_recipient_user' == $header_key && empty( $value ) ) { | |
$value = WCS_Gifting::get_recipient_user( $subscription ); | |
} | |
return $value; | |
} | |
add_filter( 'wcsie_format_export_value', 'my_custom_export_values', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you are trying to use the Subscriptions exporter, and see which subscriptions have been gifted, you will need this snippet.
Here's the exporter: https://github.com/woocommerce/woocommerce-subscriptions-importer-exporter#subscriptions-exporter
This snippet will add a "Recipient" column, which will show the recipient user ID for any gifted subs.