Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Min and Max Order Amount for Woo Payment Gateways (Raihan):
- * Añade compatibilidad con el método de pago Bizum
- * Nota: Requiere el plugin «WooCommerce Redsys Gateway Light» de José Conti
- */
- add_filter( 'mmawpg_wc_settings_tab', function( $mmawpg_settings_array ) {
- unset( $mmawpg_settings_array['mmawpg_section_end'] );
- $mmawpg_settings_array['mmawpg_bizum_lite_min'] = array(
- 'name' => esc_html__( 'Bizum (José Conti)', 'mmawpg' ),
- 'type' => 'number',
- 'desc' => esc_html__( 'Min amount', 'mmawpg' ),
- 'id' => 'mmawpg_bizum_lite_min',
- 'custom_attributes' => array(
- 'min' => '0'
- ),
- 'default' => '0',
- 'placeholder' => '0'
- );
- $mmawpg_settings_array['mmawpg_bizum_lite_max'] = array(
- 'type' => 'number',
- 'desc' => esc_html__( 'Max amount', 'mmawpg' ),
- 'id' => 'mmawpg_bizum_lite_max',
- 'custom_attributes' => array(
- 'min' => '0'
- ),
- 'default' => '0',
- 'placeholder' => '0',
- );
- $mmawpg_settings_array['mmawpg_section_end'] = array(
- 'type' => 'sectionend',
- 'id' => 'mmawpg_section_end_settings'
- );
- return $mmawpg_settings_array;
- }, 10, 1 );
- add_action('wp_ajax_mmawpg_ajax_action', 'ys_bizum_ajax_action_callback' );
- add_action('wp_ajax_nopriv_mmawpg_ajax_action', 'ys_bizum_ajax_action_callback' );
- function ys_bizum_ajax_action_callback(){
- if ( ( $mmawpg_payment_method = sanitize_text_field( $_POST['payment_type'] ) ) && $mmawpg_payment_method == 'bizumredsys' ) {
- // Nombre de la pasarela
- $GLOBALS['mmawpg_payment_method_title'] = 'Bizum';
- // Obtenemos el mínimo y máximo para Bizum
- $mmawpg_cod_min_amount = get_option( 'mmawpg_bizum_lite_min' );
- $mmawpg_cod_max_amount = get_option( 'mmawpg_bizum_lite_max' );
- // Establecemos el mínimo con base en el ajuste del envío
- $mmawpg_exc_shipping = get_option( 'mmawpg_exc_shipping_crg' );
- if( $mmawpg_exc_shipping == 'yes' ) {
- $GLOBALS['mmawpg_order_amount'] = WC()->cart->subtotal;
- } else {
- $GLOBALS['mmawpg_order_amount'] = WC()->cart->total;
- }
- // Llamamos a la clase principal del plugin para mostrar los avisos
- $mmawpg_main = new MMAWPG_Lite_Functions();
- if ( $mmawpg_cod_min_amount <= $mmawpg_cod_max_amount || $mmawpg_cod_max_amount == 0 ):
- if ( $mmawpg_cod_min_amount != 0 ):
- if ( $GLOBALS['mmawpg_order_amount'] < $mmawpg_cod_min_amount ){
- $mmawpg_main->mmawpg_print_notice( $mmawpg_cod_min_amount, 'min' );
- }
- endif;
- if ($mmawpg_cod_max_amount != 0):
- if ($mmawpg_cod_max_amount < $GLOBALS['mmawpg_order_amount']){
- $mmawpg_main->mmawpg_print_notice( $mmawpg_cod_max_amount, 'max' );
- }
- endif;
- endif;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement