Support

Account

Home Forums Add-ons Options Page Issue changing WooCommerce payment based on ACF user option

Unread

Issue changing WooCommerce payment based on ACF user option

  • I have a general Theme Options section that I created with ACF Pro and inside there is an ACF User type field that allows multiple values. The site is running WooCommerce and the basic idea is I need to able to specify certain Wholesale Users who should *only* pay by Check. All other Wholesalers and regular customers should pay by credit card.

    When I test adding one Wholesale user to this custom field, it works great (that user correctly sees the Check payment method only). However, when I add a 2nd user to this field, that user incorrectly sees the credit card payment. It’s as if my code stops going through the array as soon as it checks the first value.

    Any advice on adjusting this PHP I have in the functions would be greatly appreciated.

    
    function wholesale_disable_credit_card( $available_gateways ) {
    	global $woocommerce;
     	$current_user = wp_get_current_user();
    	$wholesale_payments = get_field('pay_by_check_only','option');
    	if (in_array( 'wholesaler', $current_user->roles ) && !empty($wholesale_payments)) {
    		 foreach($wholesale_payments as $wholesale_payment){
                if($current_user->ID == $wholesale_payment['ID']){
                     unset( $available_gateways['stripe'] );
                     break;
                } else {
    				 unset( $available_gateways['cheque'] );
                }
            }
    	} else {
    		unset( $available_gateways['cheque'] );
    	}
    	return $available_gateways;
    }
    add_filter( 'woocommerce_available_payment_gateways', 'wholesale_disable_credit_card' );
    
Viewing 1 post (of 1 total)

The topic ‘Issue changing WooCommerce payment based on ACF user option’ is closed to new replies.