I have a problem with a code. So I have five different payment methods in my site. When a customer select “Cash on delivery” as shipment method all the payment methods, exept cash on delivery, are hide.
For make that I use the follow code:
/**
* Remove payment methods when select "pagamento in contrassegno"
*/
function my_custom_available_payment_gateways( $gateways ) {
$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' );
// When 'Pagamento in contrassegno' has been chosen as shipping rate
if ( in_array( 'flat_rate:5', $chosen_shipping_rates ) ) :
// Remove the follow payments
unset( $gateways['woocommerce_payments'] );
unset( $gateways['paypal'] );
unset( $gateways['bacs'] );
unset( $gateways['klarna_payments_pay_later'] );
endif;
return $gateways;
}
add_filter( 'woocommerce_available_payment_gateways',
'my_custom_available_payment_gateways' );
The code work with all payments exept for Klarna payments that remain if I select “Pagamento in contrassegno” (cash on delivery), how can I solve that?
The site is: https://www.modacapellishop.it/