• Resolved topfgartenwelt

    (@topfgartenwelt)


    Hi,

    is it possible to make a form for selling an e-book after payment? If yes, how can I do it?

    Greetings Kathrin

    The page I need help with: [log in to see the link]

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @topfgartenwelt

    I hope you’re well today!

    The simplest way to do this would be to make a form wiht payment field – with all the data that you need – and then you could

    – include link to such PDF in the e-mail notifications
    – or set form “after submission” behavior to redirect to some download page
    – or use both.

    As for simply attaching PDF to e-mail notification, that’s not possible out of the box unless it’s a PDF automatically generated by the E2PDF plugin based on form submissions. But I believe that’s not the case and you have a ready to send ebook instead.

    So in such case it’s either above solution or you could try with a bit of custom code.

    This code should help:

    <?php
    add_filter( 'forminator_custom_form_mail_admin_headers', 'wpmudev_change_forminator_header_attachment', 10, 5 );
    function wpmudev_change_forminator_header_attachment( $headers, $custom_form, $data, $entry, $cls ) {
    	if ( $custom_form->id != 1015 ) { //Please change the form ID
    		return $headers;
    	}
    
    	$headers[] = 'X-FORMINAT-ATTCH : true';
    
    	return $headers;
    }
    
    add_filter('wp_mail', 'wpmudev_attach_pdf_forminator', 10, 1);
    function wpmudev_attach_pdf_forminator( $args ) {
    	if ( is_array( $args['headers'] ) ) {
    		foreach( $args['headers'] as $key => $value ) {
    			if ( strpos( $value, 'X-FORMINAT-ATTCH' ) !== false ) {
    $args['attachments'][] = WP_CONTENT_DIR.'/uploads/2023/05/ISAM-Sales-Leadership-Brochure-1.pdf';
    			}
    		}
    	}
    	return $args;
    }

    To use it on site:

    1. first, make sure that you have your PDF file uploaded to some folder in /wp-content/uploads

    2. then edit the code by

    a) replacing number 1015 in this line

    if ( $custom_form->id != 1015 ) { //Please change the form ID

    with an ID of your form; Form ID is the number you see in form’s shortcode

    b) and updating the path to the file in this line

    $args['attachments'][] = WP_CONTENT_DIR.'/uploads/2023/05/ISAM-Sales-Leadership-Brochure-1.pdf';

    3. and finally add the code to the site as MU plugin:

    – create an empty file with a .php extensions (eg. “forminator-attach-pdf.php”) in the “/wp-content/mu-plugins” folder of your site’s WordPress install;
    – copy and paste edited code into it
    – save the file

    It should then attach your file into e-mail notification automatically.

    Kind regards,
    Adam

    Thread Starter topfgartenwelt

    (@topfgartenwelt)

    Thank you for your answer but where I can find the form ID? I have uploaded a test-pdf. But than I don’t know what I should do further. I have created a form with a selection for e-book 1, 2 and so on.

    Greetings Kathrin

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @topfgartenwelt

    The form ID is the number you can see in form shortcode or URL when editing the form. So you can simply go to “Forminator -> Forms” page and open form in question for editing.

    If you then copy its shortcode (and paste it somehwere, eg into text editor) or if you look at the URL in browser address bar you’ll see the number there. That’s the ID you need to use in the code.

    Best regards,
    Adam

    Thread Starter topfgartenwelt

    (@topfgartenwelt)

    Ok, I think, I have found it. But what should I do, when there will be a second E-Book and there only should be a download for the ebook that was bought.

    Works it that way: the ID stays the same but the link will change when there is a second e-book?

    Is it possible to add a cover image to the selection?

    And which notification E-Mail contains the E-book now?

    Greetings Kathrin

    Plugin Support Laura – WPMU DEV Support

    (@wpmudevsupport3)

    Hi @topfgartenwelt,

    Hope this message finds you well.

    Just to be sure you get the correct ID, here is where you can find it if you edit the form:

    https://prnt.sc/cCCJoMDwksHV

    Works it that way: the ID stays the same but the link will change when there is a second e-book?

    Well, this depends if you will create a new form for the second E-book or you will just replace the link, please let us know.

    Is it possible to add a cover image to the selection?

    Our Radio and Checkbox fields do have the option to add an image for the selection.

    And which notification E-Mail contains the E-book now?

    We don’t have access to your site please check the Email Notifications settings by editing your form.

    Also, here is our Forminator Documentation link: https://wpmudev.com/docs/wpmu-dev-plugins/forminator/

    You will find examples and additional and important information about our Forminator plugin.

    Best regards,
    Laura

    Thread Starter topfgartenwelt

    (@topfgartenwelt)

    Hi Laura,

    thank you for your reply. I have taken the correct ID ??

    I want to sell 3 or 4 ebooks at the same time. The buyer should have the choice to take ebook 1, ebook 2, ebook 3 or ebook 4 at the same time. Or a combination of all them.

    How can I achieve that with forminator?

    Greetings Kathrin

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @topfgartenwelt,

    Please try this modified code:

    <?php
    
    add_filter( 'forminator_custom_form_mail_admin_headers', 'wpmudev_change_forminator_header_attachment', 10, 5 );
    function wpmudev_change_forminator_header_attachment( $headers, $custom_form, $data, $entry, $cls ) {
        if ( $custom_form->id != 4658 ) { // Replace with your actual Form ID
            return $headers;
        }
    
        $headers[] = 'X-FORMINAT-ATTCH : true';
    
        return $headers;
    }
    
    add_filter( 'wp_mail', 'wpmudev_attach_pdf_forminator', 10, 1);
    function wpmudev_attach_pdf_forminator( $args ) {
        $use_forminator_attachment = false;
    
        if ( is_array( $args['headers'] ) ) {
            foreach( $args['headers'] as $key => $value ) {
                if ( strpos( $value, 'X-FORMINAT-ATTCH' ) !== false ) {
                    $use_forminator_attachment = true;
                }
            }
        }
    
        if($use_forminator_attachment){
            $ebook_file_paths = array("one" => "/uploads/2023/12/test-one.pdf", "two" => "/uploads/2023/12/test-two.pdf"); 
    
            $submitted_data = Forminator_CForm_Front_Action::$prepared_data;
    
            if ( ! empty( $submitted_data['checkbox-1'] ) ) { // Replace 'checkbox-1' with your actual checkbox field ID
                foreach ( $submitted_data['checkbox-1'] as $key => $value ) {
                    if ( array_key_exists( $value, $ebook_file_paths ) ) {
                        $args['attachments'][] = WP_CONTENT_DIR . $ebook_file_paths[$value];
                    }
                }
            }
        }
        
        return $args;
    }

    Where you’ll need to update the above code with the form ID in the following line:

     if ( $custom_form->id != 4658 ) { 

    Suppose the form ID is 123, the above will change as:

     if ( $custom_form->id != 123 ) { 

    To make it work with the checkbox you’ll need to update the following line with your checkbox value and the path to the PDF:

       $ebook_file_paths = array("one" => "/uploads/2023/12/test-one.pdf", "two" => "/uploads/2023/12/test-two.pdf");

    where “one”, “two” are checkbox values and you’ll need to update it to your checkbox value.

    If you want to add more PDF to more values, then the line will change as:

            $ebook_file_paths = array("one" => "/uploads/2023/12/test-one.pdf", "two" => "/uploads/2023/12/test-two.pdf", "three" => "/uploads/2023/12/test-three.pdf" ); 
    

    The above code is meant to work with checkbox which has the ID checkbox-1.

    The code works when tested in my side. Please do apply it as a mu-plugins and see whether it helps.

    Please check this link on how to implement the above code as a mu-plugins:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Best Regards,

    Nithin

    Thread Starter topfgartenwelt

    (@topfgartenwelt)

    Hi,

    thank you very much for your reply.

    I have created a checkbox as you can see here: https://imgur.com/a/bziHIuR

    But I can’t find the individual ID of the Checkbox only the main ID of the form. Or isn’t that not needed and I should only change the global ID?

    Have I to check on one, two and so on?

    Greetings Kathrin

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @topfgartenwelt,

    The code needs to be updated with the form ID as instructed, other than that you’ll also have to update the given code snippet with the checkbox value.

    For example, if we take the following checkbox:

    View post on imgur.com

    The value for the check boxes are “Ebook-One”, “Ebook-Two” so the following line in the code:

     $ebook_file_paths = array("one" => "/uploads/2023/12/test-one.pdf", "two" => "/uploads/2023/12/test-two.pdf");

    The “one” and “two” in the above will get replaced with “Ebook-One”, “Ebook-Two”, ie:

      $ebook_file_paths = array("Ebook-One" => "/uploads/2023/12/test-one.pdf", "Ebook-Two" => "/uploads/2023/12/test-two.pdf");

    You’ll also have to update the URL to the correct PDF path too.

    I hope its clear now, please do check and see whether that helps.

    Kind Regards,

    Nithin

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @wpmudevsupport11,

    Since we haven’t heard from you for a while. I’ll mark this thread as resolved for now. Please feel free to open a new thread if you have new queries.

    Best Regards
    Nithin

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Download PDF after payment’ is closed to new replies.