• Resolved alortiz3

    (@alortiz3)


    alortiz3

    Hello,

    I would like to disable invoices for Credit Card users (currently members of the um_credit_card role). Is that possible with this plugin?

    Cheers

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

    (@alexmigf)

    Hi @alortiz3

    Please add the code snippet below:

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

    If you haven’t used actions/filters please read this documentation page: How to use filters

    Hello, I have the same problem,

    1. First of all, @alortiz3 how do you see the role of the payment method? I want to find in my payment methods its role.

    2. @alexmigf I just have to change “um_credit_card” for the role of my payment method in your code right?

    I am waiting for a reply, thanks to both of you.

    Thread Starter alortiz3

    (@alortiz3)

    alortiz3

    Hello yergomezz,

    Yes, all you have to do is change the payment method in the code to match the role of your payment.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    It doesn’t work, I have the following codes added in my wordpress child theme:

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

    I show you in video the codes of each payment method and as you can see the invoice is still attached and I don’t want it to be attached: https://loom.com/share/523b32ccf3cf40879096995f9e5b8afc

    Thank you for your help

    Plugin Contributor Yordan Soares

    (@yordansoares)

    @yergomezz you’re comparing payment method IDs with the user roles, that’s why those code snippet won’t work. Please see my reply in the topic you opened here: attach the invoice for certain payment methods

    Thread Starter alortiz3

    (@alortiz3)

    alortiz3

    This is the code that I have in my setting:

    /**
     * Disables Invoices for Credit Card Users
     */
    function wpr_disable_reseller_attachment( $attach, $order, $email_id, $document_type ) {
    
       // Get customer id from order
       if ( $customer_id = $order->get_customer_id() ) {
    
          // Get user by customer id 
          if ( $user = get_user_by( 'id', $user_id ) ) {
    
             // Check if user is Credit Card User or not
             return in_array( 'um_wd-credit-card', (array) $user->roles );
          }
    
       }
       return $attach;
    }
    
    add_filter( 'wpo_wcpdf_custom_attachment_condition', 'wpr_disable_reseller_attachment', 10, 4 );

    *** in my case I have a Role called “wd-credit-card”. When a user is a member of that group he/she does not get an invoice.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Disable for Credit Card Users’ is closed to new replies.