Skip to content

Instantly share code, notes, and snippets.

@ignacioribes
Created October 28, 2025 19:52
Show Gist options
  • Save ignacioribes/dd48550ce18db78814fbcc7e665755c5 to your computer and use it in GitHub Desktop.
Save ignacioribes/dd48550ce18db78814fbcc7e665755c5 to your computer and use it in GitHub Desktop.
Bloquear MP para cupones en WooCommerce (checkout bloques)
add_action('woocommerce_cart_calculate_fees', function($cart) {
if (is_admin() && !defined('DOING_AJAX')) {
return;
}
// Detecta método de pago seleccionado (solo disponible en checkout)
$chosen_payment = WC()->session->get('chosen_payment_method');
// Lista de métodos donde no se permiten cupones
$blocked_gateways = ['woo-mercado-pago-custom'];
if (in_array($chosen_payment, $blocked_gateways, true) && $cart->has_discount()) {
// Eliminar cupones aplicados
foreach ($cart->get_applied_coupons() as $coupon_code) {
$cart->remove_coupon($coupon_code);
}
// Mensaje visible en checkout (clásico y bloques)
wc_add_notice(
__('Los cupones no están permitidos con este método de pago. Se han eliminado.', 'tu-textdomain'),
'error'
);
}
}, 10, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment