Last active
November 30, 2016 18:23
-
-
Save acanza/da07aeacb8545302db4acff166686430 to your computer and use it in GitHub Desktop.
Muestra determinados métodos de pago en función del producto que haya en el carro
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
| // Muestra determinados métodos de pago en función del producto que haya en el carro | |
| add_filter( 'woocommerce_available_payment_gateways', 'show_payment_gateways_based_on_products', 1, 1 ); | |
| function show_payment_gateways_based_on_products( $methods ){ | |
| $new_methods = $methods; | |
| $product_list = array( ); //---- Aquí debes introducir el listado de IDs de productos, por ejemplo; array( 95, 112, 114 ) | |
| $payment_gateways_list = array( ); //---- Aquí debes introducir el listado de IDs de métodos de pago permitidos para estos productos, por ejemplo; array( 'paypal', 'cod' ) | |
| $cart_content = WC()->cart->cart_contents; | |
| foreach ( $cart_content as $key => $product ) { | |
| if ( in_array( $product[ 'product_id' ], $product_list ) ) { | |
| // Reset payment methods | |
| $new_methods = array(); | |
| foreach ( $methods as $key => $payment_method ) { | |
| if ( in_array( $key, $payment_gateways_list ) ) { | |
| $new_methods[ $key ] = $payment_method; | |
| } | |
| } | |
| break; | |
| } | |
| } | |
| return $new_methods; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment