Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Last active August 29, 2015 14:02
Show Gist options
  • Save remcotolsma/a16069481e5e7a4dbb8b to your computer and use it in GitHub Desktop.
Save remcotolsma/a16069481e5e7a4dbb8b to your computer and use it in GitHub Desktop.
Import Pronamic iDEAL subscriptions from CSV to Easy Digital Downloads
UPDATE
orbis_subscriptions
SET
cancel_date = NOW()
WHERE
cancel_date IS NULL
AND
type_id = 20
;
<?php
set_time_limit( 0 );
define( 'WP_USE_THEMES', false );
require( '../wp/wp-load.php' );
set_time_limit( 0 );
$row = 1;
$handle = fopen( 'import.csv', 'r' );
if ( ( $handle = fopen( 'import.csv', 'r' ) ) !== false ) {
while ( ( $data = fgetcsv( $handle, 1000, ',' ) ) !== false ) {
$num = count( $data );
$user_email = $data[0];
$post_date = $data[1];
$license = $data[2];
$expiration = $data[3];
$orbis_subscription_id = $data[4];
$orbis_post_id = $data[5];
$user = get_user_by( 'email', $user_email );
if ( $user === false ) {
$user = get_user_by( 'login', $user_email );
if ( $user === false ) {
$password = wp_generate_password();
$user_id = wp_create_user( $user_email, $password, $user_email );
}
}
if ( $user ) {
$user_id = $user->ID;
}
$post_data = array(
'post_type' => 'edd_license',
'post_title' => sprintf( 'Pronamic iDEAL - %s', $user_email ),
'post_status' => 'publish',
'post_date' => $post_date,
'post_author' => $user_id,
);
$post_id = wp_insert_post( $post_data );
if ( $post_id ) {
$post_meta = array(
'_edd_sl_download_id' => 405,
'_edd_sl_key' => $license,
'_edd_sl_user_id' => $user_id,
'_edd_sl_status' => 'inactive',
'_edd_sl_site_count' => 0,
'_edd_sl_expiration' => $expiration,
'_orbis_subscription_id' => $orbis_subscription_id,
'_orbis_post_id' => $orbis_post_id,
);
foreach ( $post_meta as $meta_key => $meta_value ) {
update_post_meta( $post_id, $meta_key, $meta_value );
}
}
echo $post_id, '<br />';
}
}
exit;
<?php
set_time_limit( 0 );
define( 'WP_USE_THEMES', false );
require( '../wp/wp-load.php' );
set_time_limit( 0 );
$row = 1;
$handle = fopen( 'import.csv', 'r' );
if ( ( $handle = fopen( 'import.csv', 'r' ) ) !== false ) {
while ( ( $data = fgetcsv( $handle, 1000, ',' ) ) !== false ) {
$num = count( $data );
$user_email = $data[0];
$post_date = $data[1];
$license = $data[2];
$expiration = $data[3];
$orbis_subscription_id = $data[4];
$orbis_post_id = $data[5];
$user = get_user_by( 'email', $user_email );
if ( $user === false ) {
$user = get_user_by( 'login', $user_email );
if ( $user === false ) {
$password = wp_generate_password();
$user_id = wp_create_user( $user_email, $password, $user_email );
}
}
if ( $user ) {
$user_id = $user->ID;
}
$post_data = array(
'post_type' => 'edd_license',
'post_title' => sprintf( 'Pronamic iDEAL - %s', $user_email ),
'post_status' => 'publish',
'post_date' => $post_date,
'post_author' => $user_id,
);
$post_id = wp_insert_post( $post_data );
if ( $post_id ) {
$post_meta = array(
'_edd_sl_download_id' => 405,
'_edd_sl_download_price_id' => 1,
'_edd_sl_key' => $license,
'_edd_sl_user_id' => $user_id,
'_edd_sl_status' => 'inactive',
'_edd_sl_site_count' => 0,
'_edd_sl_expiration' => $expiration,
'_orbis_subscription_id' => $orbis_subscription_id,
'_orbis_post_id' => $orbis_post_id,
);
foreach ( $post_meta as $meta_key => $meta_value ) {
update_post_meta( $post_id, $meta_key, $meta_value );
}
}
echo $post_id, '<br />';
}
}
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment