-
-
Save monecchi/c34606ed5dae75c739b0eadc5028a60f to your computer and use it in GitHub Desktop.
Woocommerce COD only for specific country with specific shipment rate
This file contains hidden or 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