summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-10-29 13:25:50 +0100
committerDaniel Weipert <code@drogueronin.de>2023-10-29 13:25:50 +0100
commit44cd78785e5ee3a7e783e427a119545e4fa0de40 (patch)
tree298d7b6826c88c38a87980a66821aefa566933c9
initial commitHEADmain
-rw-r--r--cf7-to-webling.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/cf7-to-webling.php b/cf7-to-webling.php
new file mode 100644
index 0000000..3b72467
--- /dev/null
+++ b/cf7-to-webling.php
@@ -0,0 +1,67 @@
+<?php
+/*
+ * Plugin Name: CF7 to Webling
+ */
+
+// @see https://plugins.trac.wordpress.org/browser/contact-form-7/trunk/includes/submission.php#L119
+// @see https://plugins.trac.wordpress.org/browser/contact-form-7/trunk/includes/contact-form.php
+add_action('wpcf7_mail_sent', function ($contactForm) {
+ $formId = 1234;
+ $apiUrl = 'https://demo.webling.ch/api/1';
+ $apiKey = '987654321';
+ $memberGroupId = 123;
+
+ if ($contactForm->id() !== $formId) {
+ return;
+ }
+
+ // @see https://stackoverflow.com/questions/42807833/how-to-capture-post-data-with-contact-form7/56655271#56655271
+ $submission = WPCF7_Submission::get_instance();
+ $data = $submission->get_posted_data();
+
+ #var_dump($data);
+ $memberData = [
+ 'properties' => [
+ 'Anrede' => $data['Anrede'][0] ?? '',
+ 'Geschlecht' => $data['Geschlecht'][0] ?? '',
+ 'Firma' => $data['Firma'],
+ 'Geburtsdatum' => $data['Geburtsdatum'],
+ #'Geburtsdatum' => date('Y-m-d', strtotime($data['Geburtsdatum'])),
+ 'Vorname' => $data['Vorname'],
+ 'Nachname' => $data['Nachname'],
+ 'Strasse / Hausnummer' => $data['Strasse'],
+ 'PLZ' => $data['PLZ'],
+ 'Ort' => $data['Ort'],
+ 'E-Mail' => $data['email'],
+ 'Telefon' => $data['Telefonnummer'],
+ 'Jahresbeitrag' => $data['Jahresbeitrag'],
+ 'Zahlungsart' => $data['Zahlungsart'][0] ?? '',
+ 'Abweichender Kontoinhaber' => empty($data['AbweichenderKontoinhaber'][0]) ? false : true,
+ 'Vorname Kontoinhaber' => $data['name-kontoinhaber'],
+ 'Nachname Kontoinhaber' => $data['nachname-kontoinhaber'],
+ 'Straße / Hausnummer Kontoinhaber' => $data['Strasse-kontoinhaber'],
+ 'PLZ/Ort Kontoinhaber' => $data['Ort-kontoinhaber'],
+ 'Kreditinstitut' => $data['Kreditinstitut'],
+ 'IBAN' => $data['IBAN'],
+ 'BIC' => $data['BIC'],
+ 'SEPA-Lastschriftmandat' => empty($data['ZustimmungSEPA'][0]) ? false : true,
+ 'Nachricht' => $data['Nachricht'],
+ 'Satzung Akzeptiert' => !! $data['Satzung'],
+ 'Datenschutz Akzeptiert' => !! $data['Datenschutz'],
+ 'Korrektheit Akzeptiert' => !! $data['Korrektheit'],
+ 'Kontaktaufnahme Akzeptiert' => !! $data['Kontakt'],
+ ],
+
+ 'parents' => [$memberGroupId],
+ ];
+
+ // @see http://demo.webling.ch/api/1/#header-php
+ $response = wp_remote_post("$apiUrl/member", [
+ 'headers' => [
+ 'apikey' => $apiKey,
+ ],
+ 'body' => json_encode($memberData),
+ ]);
+
+ #var_dump($response);exit;
+});