Created
December 5, 2014 11:34
-
-
Save salgua/30ee2bc205d71f758fd9 to your computer and use it in GitHub Desktop.
Woocommerce COD only for specific country with specific shipment rate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//enable COD only for italy | |
function payment_gateway_disable_country( $available_gateways ) { | |
global $woocommerce; | |
if ( isset( $available_gateways['cod'] ) && $woocommerce->customer->get_country() <> 'IT' ) { | |
unset( $available_gateways['cod'] ); | |
} | |
//make COD the only available gateway for flat_rate shipping method (or other unused method) | |
//you can use the label cash on delivery for flat_rate and determining the shipping cost for COD | |
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); | |
if ($chosen_methods[0] == 'flat_rate') | |
{ | |
//only cod is available | |
$available_gateways = array('cod' => $available_gateways['cod']); | |
} | |
return $available_gateways; | |
} | |
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I need to make COD only available for one state in my country along with other gateways. And disable it for other states. What changes do I make here?