Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save greenhornet79/18ec45f3f073ae95bd9a02e68bd52859 to your computer and use it in GitHub Desktop.
Save greenhornet79/18ec45f3f073ae95bd9a02e68bd52859 to your computer and use it in GitHub Desktop.
<?php
// add_action( 'admin_init', 'convert_exchange_to_leaky_paywall' );
function convert_exchange_to_leaky_paywall() {
// loop through subscribers
// see if they have a transaction
// if so, get their subscription status and subscription expiratin of the transaction
// save that data as user meta for leaky paywall
$args = array (
'role' => 'subscriber',
'number' => 200,
'offset' => 1600
);
// Create the WP_User_Query object
$wp_user_query = new WP_User_Query($args);
// Get the results
$users = $wp_user_query->get_results();
// Check for results
if ( empty($users)) {
return;
}
$settings = get_leaky_paywall_settings();
$site = '';
$mode = 'live';
foreach ( $wp_user_query->results as $user ) {
$user_id = $user->ID;
$customer = new IT_Exchange_Customer( $user_id );
$member_access = $customer->get_customer_meta( 'member_access' );
$transaction_id = key( $member_access );
if ( $transaction_id ) {
$transaction = it_exchange_get_transaction( $transaction_id );
// $subscriber_status = $transaction->get_transaction_meta( 'subscriber_status', true );
$subscriber_status = get_post_meta( $transaction_id, '_it_exchange_transaction_subscriber_status', true );
$subscriber_id = $transaction->get_transaction_meta( 'subscriber_id', true );
$meta = get_post_meta( $transaction_id );
$cart_object = get_post_meta( $transaction_id, '_it_exchange_cart_object', true );
if ( !empty( $cart_object->products ) ) {
foreach ( $cart_object->products as $product ) {
$dateformat = get_option( 'date_format' );
$expires = $transaction->get_transaction_meta( 'subscription_expires_' . $product['product_id'], true );
$expired = $transaction->get_transaction_meta( 'subscription_expired_' . $product['product_id'], true );
if ( empty( $expires ) ) {
if ( !empty( $expired ) ) {
$expires = date_i18n( $dateformat, $expired );
} else {
$expires = '';
}
} else {
$expires = date_i18n( $dateformat, $expires );
}
if ( $expires ) {
$meta = array(
'level_id' => 0,
'subscriber_id' => $subscriber_id,
'price' => '',
'description' => 'from exchange',
'plan' => 'Non-Recurring',
'expires' => $expires,
'payment_gateway' => 'exchange',
'payment_status' => 'active',
);
foreach( $meta as $key => $value ) {
update_user_meta( $user_id, '_issuem_leaky_paywall_' . $mode . '_' . $key . $site, $value );
}
// add leaky paywall userdata
// level_id
// price
// plan
// created
// expires
// gateway
// status
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment