Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Darren Peyou

    (@dpeyou)

    Hey @villehyv,

    I rewrote the snippet and it appears to function as intended with my tests. Give this a try:

    /**
     * Enable the invoice attachment only for specific payment methods
     */
    add_filter( 'wpo_wcpdf_document_is_allowed', function ( $allowed, $document ) {
    	if ( ! $document->type == 'invoice' ) { return $allowed; };
    	if ( ! $document->order ) { return $allowed; };
    	
    	$payment_methods = ['bacs'];
    	$order           = $document->order;
    	$allowed         = ( in_array( $order->get_payment_method(), $payment_methods ) ) ? true : false;
    
    	return $allowed;
    }, 10, 2 );

    And of course – if you haven’t worked with code snippets (actions/filters) or functions.php before, would you kindly read this guide? How to use filters

    Thread Starter villehyv

    (@villehyv)

    Great, thank you! Works like a charm.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Attach pdf invoice to email only with certain payment methods’ is closed to new replies.