'Hide cash on delievery for orders over certain amount of money in woocommerce

I want to have the cash on delivery option only for price below 100$ and hide it automatically when cart is above 100$. The problem is that, I have 3 different payment methods right now. Paypal, cheque and COD. When a person buy something, and choose cash on delievry method, I've written a description there saying "you can choose COD if your order is below 100$". But some people neglect it and still choose COD even their purchase is above 100$. So, I want to hide COD automatically, when a purchase is above 100$. Hence, when a purchase is above 100$, there would be just two options, Paypal and Cheque. Hope I could clarify it a bit more.

Thanks



Solution 1:[1]

add_filter( 'woocommerce_available_payment_gateways' , 'hide_payment_gateway', 20, 1);
        
function hide_payment_gateway( $gateways ){
      //change whatever amount you want
      if( WC()->cart->subtotal < 699 ){
      // then unset the 'cod' key (cod is the unique id of COD Gateway)
      unset( $gateways['cod'] );
      add_action( 'woocommerce_review_order_before_payment', 'COD_exceed_amount_before_paying_notice' );
      }
      return $gateways;
}

function COD_exceed_amount_before_paying_notice() {
      wc_print_notice( __( 'COD option not available on orders below 699.00', 'woocommerce' ), 'notice' );
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1