• Resolved muleque

    (@muleque)


    Hi,

    is there an option to not create an invoice number when a certain user makes an order?
    Identification would be best based on login name. Also role might be an option e.g. admin. Some php snippet maybe?

    Best Muleque

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hello @muleque

    Yes, should be possible, please add the code snippet below to your theme functions.php file:

    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 never worked with actions/filters, please read this documentation page: How to use filters

    Thread Starter muleque

    (@muleque)

    unfortunately this does not work for me. Any idea what could go wrong? Neither ‘Administrator’ nor my login name works. The code, however, makes total sense.
    Any advice?

    Thread Starter muleque

    (@muleque)

    Any advice on how I can debug the fields?

    Plugin Contributor kluver

    (@kluver)

    Hi @muleque,

    There was a small typo in the code snippet of my colleague. Please try the following:

    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 );
    Thread Starter muleque

    (@muleque)

    Awesome. Your snippet did the job perfectly!
    Many thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘No invoice number for certain users’ is closed to new replies.