I'm trying to hide the Bank Account Transfer payment method when the order is less than $500 but the code is not working. Can you help me to find the error?
add_filter( 'woocommerce_available_payment_gateways', 'show_hide_payment_methods_on_checkout' , 1 );
function show_hide_payment_methods_on_checkout( $available_gateways ) {
// Set minimum cart total
$minimum_order_total = 500;
// Get the order total
$order_total = WC()->cart->get_total( 'edit' );
echo 'Final Price: ' . $order_total;
// Check if the order total is less than or equal to the minimum
if ( $order_total <= $minimum_order_total ) {
// Check if 'bacs' payment gateway is available and unset it
if ( isset( $available_gateways['bacs'] ) ) {
unset( $available_gateways['bacs'] );
}
}
return $available_gateways;
}
Try the following instead:
Code goes in functions.php file of your child theme (or in a plugin). Tested and works.