{"id":5671953,"date":"2015-01-14T18:52:57","date_gmt":"2015-01-14T18:52:57","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/programatically-adding-subscriptions\/"},"modified":"2016-08-22T15:24:34","modified_gmt":"2016-08-22T15:24:34","slug":"programatically-adding-subscriptions","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/programatically-adding-subscriptions\/","title":{"rendered":"Programatically adding subscriptions"},"content":{"rendered":"<p>Hello! I&#8217;m working on integrating MailPoet and WooCommerce. I can add a new subscriber using the code from http:\/\/support.mailpoet.com\/knowledgebase\/plugin-form-integrate\/ but the problem is, if a subscriber already exists, it won&#8217;t add a new newsletter subscription. I have it set to check if the user already exists, but can&#8217;t figure out how to add one for someone who is already in there. Here&#8217;s the code: <\/p>\n<pre><code>$data_subscriber = array(&#039;user&#039; =&gt; $user_data, &#039;user_list&#039; =&gt; array(&#039;list_ids&#039; =&gt; $list_array));\n\n\/\/ see if the subscriber already exists\n$sSQL = &quot;SELECT user_id FROM wp_wysija_user WHERE email=&#039;&quot;.$item[&#039;item_meta&#039;][&#039;Attendee - Email Address&#039;][0].&quot;&#039;&quot;;\n$checksub = $wpdb-&gt;get_results( $sSQL );\nif ($checksub) {\n\tforeach ($checksub as $c) {\n\t\t$added_user_id = $c-&gt;user_id;\n\t\t$helper_user = WYSIJA::get(&#039;user&#039;, &#039;helper&#039;);\n\t\t$helper_user-&gt;subscribe($added_user_id, TRUE, FALSE, $list_array);\n\t}\n} else {\n\t\/* @var $helper_user WYSIJA_help_user *\/\n\t$helper_user = WYSIJA::get(&#039;user&#039;, &#039;helper&#039;);\n\t$helper_user-&gt;no_confirmation_email = TRUE;\n\t$added_user_id = $helper_user-&gt;addSubscriber($data_subscriber);\n\t$helper_user-&gt;confirm_user($added_user_id);\n\t$helper_user-&gt;subscribe($added_user_id, TRUE, FALSE, $list_array);\n}<\/code><\/pre>\n<p>Any ideas? Thanks so much in advance!!<\/p>\n<p>https:\/\/wordpress.org\/plugins\/wysija-newsletters\/<\/p>\n","protected":false},"template":"","class_list":["post-5671953","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5671953","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5671953\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=5671953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}