If you use Woocommarce, you must have come across the problem of dependence of the selected type of delivery and the type of payment, or rather the lack of it. This means that if the customer, for example, chose cash on delivery, he could still make a transfer or use the payment gate. To remove the above-mentioned problem, just add the following code in the theme folder:
--?php /** * zalleznosc miedzy platnoscia a dostawa */ function my_custom_available_payment_gateways( $gateways ) { $chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' );<br ?--> // When 'local delivery' has been chosen as shipping rate if ( ! in_array( 'flexible_shipping_1_1', $chosen_shipping_rates ) ) : // id dostawy
unset( $gateways['bacs'] );
unset( $gateways['transferuj'] );
elseif ( ! in_array( 'flexible_shipping_1_2', $chosen_shipping_rates ) ) :
// id dostawy nr 2
unset( $gateways['cod'] );
endif;
return $gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'my_custom_available_payment_gateways' );
?>