0

I would like to know if its possible to send CF7 form submission data to a plugin to process a payment using an API.

The workflow should be as below,

User fills in form on frontend (CF7 form) --> Submits the form --> Before mail is sent data is passed to plugin (plugin A) --> Plugin A Gets the data and processes payment (using payment info submitted) --> Returns data to functions.php --> Submits return data to another plugin (plugin B) --> Plugin B then stores the data in database --> returns true --> Mail is sent (via CF7)

I have looked at hooks but I am not sure if they work in that manner.

I have build the plugin so that it works with the Payment Gateway, however I am unable to find a way to actually pass the data from the CF7 form submission to the plugin.

Further Info --

I have built the plugin using OOP methods.

1

A complete answer would be a little complicated since 'plugin A' and 'plugin B' should be analized in-depth so check for available hooks and filters, but if I understand you wrote your own plugin so you have full control on it. That said, a starting point to get submitted data from CF7 is the following:

add_action("wpcf7_submit", "Stack_308450_forward_cf7", 10, 2);

function Stack_308450_forward_cf7($form, $result) {
    // var_dump($submission->status);
    $submission = WPCF7_Submission::get_instance();
    if ($result["status"] == "mail_sent") {
        $posted_data = $submission->get_posted_data();
        Stack_308450_wpcf7_posted_data($posted_data);
    }
};
function Stack_308450_wpcf7_posted_data($posted_data){
    //do something here
}

I've personally implemented some functions on CF7 submission: in this case we're processing data after mail sent so you should indagate yourself if you find a more appropriate hook such as "wpcf7_before_send_mail":

function action_wpcf7_before_send_mail( $contact_form ) { 
  // var_dump($contact_form);
};

add_action( 'wpcf7_before_send_mail', 'action_wpcf7_before_send_mail', 10, 1 ); 

Consider also issue regarding validation on submission which are also involved in this process.

Here follows a List of available CF7 hooks»

1
  • Thank you for your reply. Yup after some reading I think thats the way to go.. I wanted to try keep it simple and try create its own hook which maybe fired within the function I called within the hook wpcf7_before_send_mail. Just thought it might be better to have the plugin I build not rely on CF7 directly, however dont think thats possible and might complicate things quite a bit.
    – Adrian
    Jul 16 '18 at 3:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.