Advertisement
YordanSoares

Min and Max Order Amount for Woo Payment Gateways (Raihan): Añade compatibilidad con Bizum

Jan 20th, 2024 (edited)
1,067
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.90 KB | Software | 0 0
  1. <?php
  2. /**
  3.  * Min and Max Order Amount for Woo Payment Gateways (Raihan):
  4.  * Añade compatibilidad con el método de pago Bizum
  5.  * Nota: Requiere el plugin «WooCommerce Redsys Gateway Light» de José Conti
  6.  */
  7. add_filter( 'mmawpg_wc_settings_tab', function( $mmawpg_settings_array ) {
  8.     unset( $mmawpg_settings_array['mmawpg_section_end'] );
  9.     $mmawpg_settings_array['mmawpg_bizum_lite_min'] = array(
  10.         'name' => esc_html__( 'Bizum (José Conti)', 'mmawpg' ),
  11.         'type' => 'number',
  12.         'desc' => esc_html__( 'Min amount', 'mmawpg' ),
  13.         'id'   => 'mmawpg_bizum_lite_min',
  14.         'custom_attributes' => array(
  15.             'min'   => '0'
  16.         ),
  17.         'default' => '0',
  18.         'placeholder' => '0'
  19.     );
  20.     $mmawpg_settings_array['mmawpg_bizum_lite_max'] = array(
  21.         'type' => 'number',
  22.         'desc' => esc_html__( 'Max amount', 'mmawpg' ),
  23.         'id'   => 'mmawpg_bizum_lite_max',
  24.         'custom_attributes' => array(
  25.             'min'   => '0'
  26.         ),
  27.         'default' => '0',
  28.         'placeholder' => '0',
  29.     );
  30.     $mmawpg_settings_array['mmawpg_section_end'] = array(
  31.         'type' => 'sectionend',
  32.         'id' => 'mmawpg_section_end_settings'
  33.     );
  34.     return $mmawpg_settings_array;
  35. }, 10, 1 );
  36. add_action('wp_ajax_mmawpg_ajax_action', 'ys_bizum_ajax_action_callback' );
  37. add_action('wp_ajax_nopriv_mmawpg_ajax_action', 'ys_bizum_ajax_action_callback' );
  38. function ys_bizum_ajax_action_callback(){
  39.     if ( ( $mmawpg_payment_method = sanitize_text_field( $_POST['payment_type'] ) ) && $mmawpg_payment_method == 'bizumredsys' ) {
  40.         // Nombre de la pasarela
  41.         $GLOBALS['mmawpg_payment_method_title'] = 'Bizum';
  42.  
  43.         // Obtenemos el mínimo y máximo para Bizum
  44.         $mmawpg_cod_min_amount = get_option( 'mmawpg_bizum_lite_min' );
  45.         $mmawpg_cod_max_amount = get_option( 'mmawpg_bizum_lite_max' );
  46.  
  47.         // Establecemos el mínimo con base en el ajuste del envío
  48.         $mmawpg_exc_shipping = get_option( 'mmawpg_exc_shipping_crg' );
  49.         if( $mmawpg_exc_shipping == 'yes' ) {
  50.             $GLOBALS['mmawpg_order_amount'] = WC()->cart->subtotal;
  51.         } else {
  52.             $GLOBALS['mmawpg_order_amount'] = WC()->cart->total;
  53.         }
  54.         // Llamamos a la clase principal del plugin para mostrar los avisos
  55.         $mmawpg_main = new MMAWPG_Lite_Functions();
  56.         if ( $mmawpg_cod_min_amount <= $mmawpg_cod_max_amount || $mmawpg_cod_max_amount == 0 ):
  57.         if ( $mmawpg_cod_min_amount != 0 ):
  58.         if ( $GLOBALS['mmawpg_order_amount'] < $mmawpg_cod_min_amount ){
  59.             $mmawpg_main->mmawpg_print_notice( $mmawpg_cod_min_amount, 'min' );
  60.         }
  61.         endif;
  62.         if ($mmawpg_cod_max_amount != 0):
  63.         if ($mmawpg_cod_max_amount < $GLOBALS['mmawpg_order_amount']){
  64.             $mmawpg_main->mmawpg_print_notice( $mmawpg_cod_max_amount, 'max' );
  65.         }
  66.         endif;
  67.         endif;
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement