Skip to content

Instantly share code, notes, and snippets.

@fgrweb
Last active January 23, 2022 07:40
Show Gist options
  • Select an option

  • Save fgrweb/41179eb9c0be0b651bef4e71f53f22e8 to your computer and use it in GitHub Desktop.

Select an option

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
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