Payment Methods per CPT

This topic contains 4 replies, has 3 voices, and was last updated by  Samantha 4 years, 9 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #4378

    Samantha
    Free User
    Post count: 33

    Hey guys,

    We’re using these two payment methods:

    PayPal
    Pre-Bank Transfer

    We would like to hide the Pre-Bank transfer for all but one package on one CPT. Is there a way to do that?

    If CPT = gd_apartments
    and if package ID = 7
    show pre-bank transfer

    all other packages, hide pre-bank transfer

    Thanks for your help!

    #4379

    Samantha
    Free User
    Post count: 33
    This reply has been marked as private.
    #4381

    Alex Rollin
    Moderator
    Post count: 27815

    There isn’t a setting or option to show or hide based on the item, but I will check with the developers in case there is a workaround.

    #4382

    Kiran
    Moderator
    Post count: 7069

    Hi Misty,

    Try following PHP snippet do disable pre bank transfer gateway for expect one specific invoice item.

    
    
    /**
     * Filter payment gateways on checkout page.
     */
    function wpi_snippet_200320_payment_gateways_on_cart( $gateways = array() ) {
    	$invoice = wpinv_get_invoice( 0, true );
    	
    	if ( ! empty( $invoice ) && ( $items = $invoice->get_items() ) ) {
    		foreach ( $items as $key => $item ) {
    			if ( ! empty( $item ) && ! empty( $item['id'] ) && $item['id'] == 84 ) { // 84 is Item ID from Invoicing > Items > ID
    				
    			} else {
    				if ( isset( $gateways['bank_transfer'] ) ) {
    					unset( $gateways['bank_transfer'] ); // Unset gateway
    				}
    			}
    		}
    	}
    	return $gateways;
    }
    add_filter( 'wpinv_payment_gateways_on_cart', 'wpi_snippet_200320_payment_gateways_on_cart', 20, 1 );

    Thanks,
    Kiran

    #4387

    Samantha
    Free User
    Post count: 33

    Thank you Kiran!

    That was, for some reason unsetting the gateway on all packages, including the one I put the ID in for. However, I realized I can just set the packages to recurring and that will hide the pre-bank transfer. Which, is fine because I wanted it to be recurring anyway.

    Thanks so much for all your help!

Viewing 5 posts - 1 through 5 (of 5 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket