Last active
January 23, 2022 07:40
-
-
Save fgrweb/41179eb9c0be0b651bef4e71f53f22e8 to your computer and use it in GitHub Desktop.
Mostrar/ocultar métodos de pago en función de las variaciones de un producto en WooCommerce
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_filter( 'woocommerce_available_payment_gateways', 'fgr_desactivar_metodos_de_pago' ); | |
| function fgr_desactivar_metodos_de_pago( $available_gateways ) { | |
| if ( ! is_checkout() ) return $available_gateways; | |
| $unset = false; | |
| $items = WC()->cart->get_cart(); | |
| foreach ( $items as $item => $values ) { | |
| $producto = $values['data']; | |
| $attribute = $producto->get_attribute('pa_atributo'); | |
| if ( 'Mi atributo' === $attribute ) { | |
| $unset = true; | |
| } | |
| } | |
| if ( $unset ) { | |
| unset( $available_gateways['bacs'] ); | |
| unset( $available_gateways['cheque'] ); | |
| unset( $available_gateways['redsys'] ); | |
| } else{ | |
| unset( $available_gateways['cod'] ); | |
| } | |
| return $available_gateways; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment