From e71ad956ff43fcd90a443c00f96d368b1f9cf490 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 31 Jul 2018 11:38:42 -0400 Subject: [PATCH] When updating the billing info add account if non exists. Setting up an account in billing when updating billing info if none exists. --- classes/billingSupport.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 6417bc5..d8870fa 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -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; -- 2.17.1