Created
October 28, 2025 19:52
-
-
Save ignacioribes/dd48550ce18db78814fbcc7e665755c5 to your computer and use it in GitHub Desktop.
Bloquear MP para cupones en WooCommerce (checkout bloques)
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
| 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