How To Hide Card Payment Option If Cart Items Have Diferrent Availability

I want to change step_four.tpl or payments_method.tpl to show only offline payment options if any of the session cart items have "Limited stock" or "Out of stock" availability.

What and where do I need to change? What is the variable for the cart items availability?

I want to change step_four.tpl or payments_method.tpl to show only offline payment options if any of the session cart items have "Limited stock" or "Out of stock" availability.

What and where do I need to change? What is the variable for the cart items availability?

It is required to extend the fn_prepare_checkout_payment_methods function (app/functions/fn.cart.php). Please check $cart['products'] array to see all extra parameters of each item

It is required to extend the fn_prepare_checkout_payment_methods function (app/functions/fn.cart.php). Please check $cart['products'] array to see all extra parameters of each item

Thanks for your reply.

Please let me know if this approach is correct:

1. I should create init.php and func.php in app/addons/my_changes

2. Register the prepare_checkout_payment_methods hook in init.php

3. Create a function called fn_my_changes_prepare_checkout_payment_methods

Yes, the described way is correct

Yes, the described way is correct

Thanks for your help.

I've managed to get the availability for each product in the cart and check if they are in stock. However I'm a bit confused as to how to overwrite the function output in order to completely eliminate the card payment option.

If you can please have a quick look and point me in the right direction, here's what I've done so far:

if ( !defined(‘AREA’) ) { die(‘Access denied’); }

function fn_my_changes_prepare_checkout_payment_methods($cart, $auth, $payment_groups)
{
$keys = array_keys($cart[‘products’]);

 if($keys != NULL){
	for($i = 0; $i < count($cart['products']); $i++) {
    		foreach($cart['products'][$keys[$i]] as $key => $value) {
        		if($key == "product_id") 
        			$product_ids[] = $value;
    		       }	
		}
	
       foreach ($product_ids as $product_id) {
       // "9" is the feature id for stock availability variants   
       $variant_options[] = db_get_field("SELECT variant_id FROM ?:product_features_values WHERE product_id = ?i AND feature_id = ?s", $product_id, "9");
    }

   $payment_methods = fn_get_payments(array('usergroup_ids' => $auth['usergroup_ids']));
   // "2" - variant_id for "In stock"
   // compare number of products in stock to number of products in cart
   if(count(array_keys($variant_options, '2')) != count($variant_options)){
	foreach ($payment_methods as $k => $v){
	   // "P" - payment gateway processor type
           if ($payment_methods[$k]['processor_type'] == 'P') {
	       unset($payment_methods[$k]);
	    }

         $payment_groups[$v['payment_category']][$k] = isset($payment_methods[$k]) ? $payment_methods[$k] : null;
         }
       }			
}		    

return $payment_groups;

}

Right now, it removes the payment method array with the processor type value "P" from the payment methods array but it doesn't change anything in the checkout payment options.

Add & before $payment_groups in the list of arguments. E.g.

function fn_my_changes_prepare_checkout_payment_methods($cart, $auth, &$payment_groups)