Code-Snippets-Functions/Execute a function on a child site/WooCommerce/hiding-cod-if-subtotal-is-under-a-certain-amount-in-subtotal.txt

10 lines
383 B
Text

add_filter( 'woocommerce_available_payment_gateways', 'ts_disable_cod' );
function ts_disable_cod( $available_gateways ) {
// Target Checkout to avoid warnings or errors
if( is_checkout() && ! is_wc_endpoint_url() && WC()->cart ) {
if ( WC()->cart->subtotal <= 10 ) {
unset( $available_gateways['cod'] );
}
}
return $available_gateways;
}