Skip to content

Instantly share code, notes, and snippets.

@maxkostinevich
Last active March 12, 2018 19:57
Show Gist options
  • Save maxkostinevich/19175b6a1ff40aabf667b5d1a54a72a9 to your computer and use it in GitHub Desktop.
Save maxkostinevich/19175b6a1ff40aabf667b5d1a54a72a9 to your computer and use it in GitHub Desktop.
WooCommerce - How to change available payment methods depending on cart total
<?php
// Change available payment methods depending on cart total
function payment_gateway_disable_payment_method( $available_gateways ) {
$cart_total = WC()->cart->total;
$condition_price = 1000.00;
if ( isset($available_gateways['cod']) && ($cart_total > $condition_price) ) {
unset( $available_gateways['cod'] ); // Disable "Cash on Delivery" payment method
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_payment_method' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment