Im klassischen Checkout-Ablauf könnte dies leicht mit dem Filter „woocommerce_available_ payment_gateways“ erreicht werden:
Code: Select all
add_filter('woocommerce_available_payment_gateways', 'custom_restrict_cod_for_slovenia');
function custom_restrict_cod_for_slovenia($gateways) {
if (is_admin()) return $gateways;
if (isset($gateways['cod'])) {
$shipping_country = WC()->customer->get_shipping_country();
if ($shipping_country !== 'DE') {
unset($gateways['cod']);
}
}
return $gateways;
}
Ich habe auch versucht, mich wie folgt in woocommerce_store_api_paid_methods einzubinden:
Code: Select all
add_filter('woocommerce_store_api_payment_methods', 'custom_cod_for_si_only', 10, 2);
function custom_cod_for_si_only($gateways, $request) {
if (isset($gateways['cod'])) {
if (
isset($request['shipping_address']['country']) &&
$request['shipping_address']['country'] !== 'DE'
) {
unset($gateways['cod']);
}
}
return $gateways;
}
Mobile version