• Resolved curtisagitate

    (@curtisagitate)


    Hi there,

    Is there a hook/filter/function to stop invoices from being sent to users with certain role?

    Thanks
    C

Viewing 1 replies (of 1 total)
  • Hello @curtisagitate,

    If you want to disable the PDF Invoice altogether, try with this code snippet:

    add_filter('wpo_wcpdf_document_is_allowed', function( $allowed, $document ) {
    	if ( !empty( $order = $document->order ) && $document->get_type() == 'invoice' ) {
    		$user = $order->get_user();
    		// based on user login
    		if ( $user->user_login == 'some_username' ) { // replace with another user login name
    			$allowed = false;
    		}
    		// based on user role
    		if ( in_array( 'administrator', (array) $user->roles ) ) { // replace with another role
    			$allowed = false;
    		}
    	}
    	return $allowed;
    }, 10, 2 );

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

    However, if you only want to disable the attachment of the PDF Invoice, but still be able to manually create it, replace wpo_wcpdf_document_is_allowed with this wpo_wcpdf_custom_attachment_condition.

Viewing 1 replies (of 1 total)
  • The topic ‘Userrole based stop invoices?’ is closed to new replies.