Last active
July 24, 2024 16:34
-
-
Save joseconti/bb7d104128659a08dbf7be07d70fe059 to your computer and use it in GitHub Desktop.
Cambiar de terminal dependiendo de la categoría del producto en WooCommerce Redsys Gateway
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
<?php | |
// Filtro que solo funciona en el plugin premium WooCommerce Redsys Gateway https://woocommerce.com/products/redsys-gateway | |
add_filter( 'redsys_modify_data_to_send', 'datos_modificados_pasarela_pago_en_redsys' ); // Filtro para «Redsys redirección (por Jose Conti)» | |
function datos_modificados_pasarela_pago_en_redsys( $redsys_data_send ) { | |
$order_id = WCRed()->clean_order_number( $redsys_data_send['transaction_id2'] ); | |
$order = new WC_Order( $order_id ); | |
$items = $order->get_items(); | |
foreach ( $items as $key => $item ) { | |
$product_id = $item['product_id']; | |
$terms = get_the_terms( $product_id, 'product_cat' ); | |
foreach ( $terms as $term ) { | |
// Categories por slug | |
$product_cat_slug = $term->slug; | |
if ( 'categoria' === $product_cat_slug ) { | |
$redsys_data_send['customer'] = 'XXXXXXXXXXXXX'; | |
$redsys_data_send['DSMerchantTerminal'] = 'X'; | |
$redsys_data_send['secretsha256'] = 'XXXXXXXXXXXXXXXXXXXXXXX'; | |
return $redsys_data_send; | |
} | |
if ( 'categoria-2' === $product_cat_slug ) { | |
$redsys_data_send['customer'] = 'XXXXXXXXXXXXX'; | |
$redsys_data_send['DSMerchantTerminal'] = 'X'; | |
$redsys_data_send['secretsha256'] = 'XXXXXXXXXXXXXXXXXXXXXXX'; | |
return $redsys_data_send; | |
} | |
} | |
} | |
return $redsys_data_send; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Este código solo sirve para mi plugin WooCommerce Redsys Gateway
https://plugins.joseconti.com/product/plugin-woocommerce-redsys-gateway/