Userrole based stop invoices? | WordPress.org

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.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Your Advertisement Here