public function updateMembershipProductIds() { global $wpdb; $output = false; // Check for subscriptions lacking a product id $sql = 'SELECT id from ' . Cart66Common::getTableName('account_subscriptions') . " WHERE product_id='0' OR product_id IS NULL"; $needyAccountSubscriptions = $wpdb->get_results($sql); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] " . count($needyAccountSubscriptions) . " accounts found that need to have a product id updated."); if (count($needyAccountSubscriptions) > 0) { // accounts needing product id have been found foreach ($needyAccountSubscriptions as $accountId) { $account = new Cart66AccountSubscription($accountId->id); $accountProductId = $account->getProductId(); if ($accountProductId && !is_array($accountProductId)) { $account->updateProductId($accountProductId); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Adding Product id: {$accountProductId} to account id: {$accountId->id} "); } elseif (is_array($accountProductId)) { $latestProductId = $account->findLatestProductId($accountProductId); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Multiple products found for account {$accountId->id}"); if ($latestProductId) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Latest membership product id found, id: {$latestProductId}"); $account->updateProductId($latestProductId); } } else { $output[] = "The subscription id:{$accountId->id} belonging to {$account->billing_first_name} {$account->billing_last_name} does not have a product ID associated with it. This will prevent notifications from being sent out. Please <a href='" . Cart66Common::replaceQueryString('page=cart66-accounts&accountId=' . $account->account_id) . "'>edit the account</a> and select a product ID."; Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] No products were found matching the feature level and subscription plan name of the account id: {$accountId->id}"); } } } return $output; }