When updating the billing info add account if non exists.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 31 Jul 2018 15:38:42 +0000 (11:38 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 31 Jul 2018 15:38:42 +0000 (11:38 -0400)
Setting up an account in billing when updating billing info if none
exists.

classes/billingSupport.php

index 6417bc5..d8870fa 100644 (file)
@@ -1572,9 +1572,9 @@ class GlmBillingSupport
     public function saveContactBillingData( $ref_dest )
     {
         $required_fields = $errors = array();
-        $city_name = '';
-        $billingAccount = new GlmDataAccounts( $this->wpdb, $this->config );
-        $billingFields  = $billingAccount->fields;
+        $city_name       = '';
+        $billingAccount  = new GlmDataAccounts( $this->wpdb, $this->config );
+        $billingFields   = $billingAccount->fields;
         if ( $billingFields ) {
             foreach( $billingFields as $field_name => $field ) {
                 if ( $field['required'] ) {
@@ -1702,6 +1702,21 @@ class GlmBillingSupport
                         $billing_updated_format,
                         array( '%d' )
                     );
+                } else {
+                    // Get the member name
+                    $member_name = $this->wpdb->get_var( "SELECT name FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX . "members WHERE id = $member_id" );
+                    // Need to create an account record
+                    $billing_updated['ref_name']         = $member_name; // Use members name
+                    $billing_updated['ref_dest']         = $member_id;
+                    $billing_updated['anniversary_date'] = date('Y-m-d H:i:s');
+                    $billing_updated_format[]            = '%s';
+                    $billing_updated_format[]            = '%d';
+                    $billing_updated_format[]            = '%s';
+                    $this->wpdb->insert(
+                        GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts',
+                        $billing_updated,
+                        $billing_updated_format
+                    );
                 }
             } else {
                 return $errors;