Skip to content

Instantly share code, notes, and snippets.

@kloon
Created January 30, 2014 08:23
Show Gist options
  • Save kloon/8704570 to your computer and use it in GitHub Desktop.
Save kloon/8704570 to your computer and use it in GitHub Desktop.
WooCommerce import Points & Rewards using Customer Order CSV Importer
<?php
add_action( 'woocommerce_api_points_rewards_custom_generator', 'wc_points_rewards_generate_custom_points' );
function wc_points_rewards_generate_custom_points() {
$customers = get_users( array(
'meta_key' => 'wc_points_balance'
) );
foreach ( $customers as $customer ) {
$points = get_user_meta( $customer->ID, 'wc_points_balance', true );
if ( $points > 0 ) {
if ( WC_Points_Rewards_Manager::increase_points( $customer->ID, $points, 'IMPORT' ) ) {
print $customer->user_nicename . ', ' . $points . ' imported<br>';
delete_user_meta( $customer->ID, 'wc_points_balance' );
wp_cache_delete( $customer->ID, 'user' . '_meta' );
} else print 'Import Failed: ' . $customer->user_nicename;
}
}
die();
}
@C00woot
Copy link

C00woot commented Jun 12, 2019

Does not work. I used 'wc_points_balance' as the field name, nothing happens.

@tommyshellberg
Copy link

Does not work. I used 'wc_points_balance' as the field name, nothing happens.

The meta key is just points_balance @C00woot

@darcyhooper
Copy link

Hi has anyone got this to work? I have the code loaded in functions.php and when I run the importer using a simple test with a single email address and points column (labelled wc_points_balance) it asks to map the column headers to the customer database. of course the points fields are not there, so I wonder how this is achieved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment