• Hi there,
    I want to sometimes, send a PDF on the completed order email.
    I created a child theme, using a plugin that makes the job. And after searching I found this code that I’m pasting after this : // END ENQUEUE PARENT ACTION on my functions.php child theme.
    On the parent theme functions.php it is working, but when I paste on child it doesn’t.

    add_filter( 'woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 3);
    
    function attach_terms_conditions_pdf_to_email ( $attachments, $status , $order ) {
    	$allowed_statuses = array( 'customer_completed_order' );
    
    	if( isset( $status ) && in_array ( $status, $allowed_statuses ) ) {
    		$pdf_name = get_post_meta( get_the_id(), 'email_fatura', true );
    		$pdf_path = get_home_path() . '/Faturas/GestaoDespesas/' . $pdf_name;
    		$attachments[] = $pdf_path;
    	}
    
    	return $attachments;
    }

    Thank you in advance for any kind of help!

    • This topic was modified 3 years, 11 months ago by ticoocit.
    • This topic was modified 3 years, 11 months ago by ticoocit.

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @ticoocit!

    That is very strange!

    Have you tried using a plugin like https://www.ads-software.com/plugins/code-snippets/ to add the code? That way you won’t need to add the code to the parent themes’ functions.php and risk it being wiped clean with the next theme update.

    Cheers!

    Thread Starter ticoocit

    (@ticoocit)

    First of all let me thank you for reaching me out @rynald0s.
    Previously I’ve created a custom plugin to get the billing_email, with the help of an user.
    So I managed to make this attached PDF work, adding the following code to the plugin:

    add_filter( 'woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 3);
    
    function attach_terms_conditions_pdf_to_email ( $attachments, $status , $order ) {
    	$allowed_statuses = array( 'customer_completed_order' );
    
    	if( isset( $status ) && in_array ( $status, $allowed_statuses ) ) {
    		$pdf_name = get_post_meta( get_the_id(), 'email_fatura', true );
    		$pdf_path = get_home_path() . '/Faturas/GestaoDespesas/' . $pdf_name;
    		$attachments[] = $pdf_path;
    	}
    
    	return $attachments;
    }

    This means, that it is going to look for post_meta – email_fatura (translated: email_invoice) and pass the value to pdf_name.
    So far it’s working good if I put some value on post_meta. But if I don’t it sends a file as well, called “GestaoDespesas”. But I don’t want that, if there is no value, it shouldn’t send anything.

    Can you please help me on that?

    Thank you in advance for your help.

    Best regards.

    • This reply was modified 3 years, 11 months ago by ticoocit.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘attach a PDF on a completed order email’ is closed to new replies.