Skip to main content
Paga con ZIGI uses WordPress hooks and filters to integrate seamlessly with WooCommerce and allow for extensibility. This page documents all available hooks, filters, and actions.

WooCommerce Integration Hooks

woocommerce_payment_gateways

Registers the ZIGI payment gateway class with WooCommerce. Type: Filter
File: paga-con-zigi.php:27
Function: zigi_payment_add_gateway_class
add_filter('woocommerce_payment_gateways', 'zigi_payment_add_gateway_class');

function zigi_payment_add_gateway_class($gateways)
{
    $gateways[] = 'Zigi_Payment_WC_Gateway';
    return $gateways;
}

woocommerce_update_options_payment_gateways_zigi_payment

Triggered when admin saves the payment gateway settings. Type: Action
File: paga-con-zigi.php:90
Class Method: Zigi_Payment_WC_Gateway::process_admin_options
add_action(
    'woocommerce_update_options_payment_gateways_' . $this->id,
    array($this, 'process_admin_options')
);

WordPress Core Hooks

before_woocommerce_init

Declares compatibility with WooCommerce High-Performance Order Storage (HPOS). Type: Action
File: paga-con-zigi.php:39
Function: zigi_payment_hpos_compatibility
Priority: 10 (default)
add_action('before_woocommerce_init', 'zigi_payment_hpos_compatibility');

function zigi_payment_hpos_compatibility()
{
    if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) {
        \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility(
            'custom_order_tables',
            __FILE__,
            true
        );
    }
}
This hook ensures the plugin works correctly with WooCommerce’s modern order storage system introduced in WooCommerce 7.0+.

plugins_loaded

Initializes the payment gateway class after all plugins are loaded. Type: Action
File: paga-con-zigi.php:52
Function: zigi_payment_init_gateway_class
Priority: 11
add_action('plugins_loaded', 'zigi_payment_init_gateway_class', 11);

function zigi_payment_init_gateway_class()
{
    if (class_exists('WC_Payment_Gateway')) {
        require_once plugin_dir_path(__FILE__) . 'functions.php';
        
        if (!class_exists('Zigi_Payment_WC_Gateway')) {
            class Zigi_Payment_WC_Gateway extends WC_Payment_Gateway
            {
                // Gateway implementation
            }
        }
    }
}
The priority is set to 11 to ensure WooCommerce is fully loaded before initializing the gateway.

Asset Enqueue Hooks

admin_enqueue_scripts

Enqueues admin scripts and styles for the gateway settings page. Type: Action
File: functions.php:18
Function: zigi_payment_admin_script
add_action('admin_enqueue_scripts', 'zigi_payment_admin_script');

function zigi_payment_admin_script()
{
    if (!did_action('wp_enqueue_media')) {
        wp_enqueue_media();
    }
    
    wp_enqueue_script(
        'zigi-payment-admin',
        plugins_url('/assets/woopro.js', __FILE__),
        array('jquery'),
        '1.1',
        false
    );
    
    wp_enqueue_style(
        'zigi-payment-admin',
        plugins_url('/assets/woopro.css', __FILE__),
        array(),
        '1.1'
    );
}

wp_enqueue_scripts

Enqueues frontend scripts, styles, and localized data for the payment popup. Type: Action
File: functions.php:99
Function: zigi_payment_front_script
add_action('wp_enqueue_scripts', 'zigi_payment_front_script');

function zigi_payment_front_script()
{
    wp_enqueue_script(
        'zigi_payment_qr',
        plugins_url('assets/woopro-front.js', __FILE__),
        array('jquery'),
        '1.1',
        false
    );
    
    wp_enqueue_style(
        'zigi_payment_qr',
        plugins_url('assets/woopro-front.css', __FILE__),
        array(),
        '1.1'
    );
    
    // Localize AJAX URL and nonce
    wp_localize_script(
        'zigi_payment_qr',
        'kwajaxurl',
        array(
            'ajaxurl' => admin_url('admin-ajax.php'),
            'nonce'   => wp_create_nonce('zigi_payment_qr_nonce')
        )
    );
    
    // Localize translatable strings
    wp_localize_script(
        'zigi_payment_qr',
        'kwp_translate',
        array(
            'kwp_pqr_btn_continue'  => __('Continuar', 'paga-con-zigi'),
            'kwp_pqr_upload_images' => __('Por favor sube solo imágenes', 'paga-con-zigi'),
        )
    );
}

Upload and File Handling Hooks

upload_dir

Modifies the upload directory to store payment receipts in a custom subdirectory. Type: Filter
File: functions.php:169
Function: zigi_payment_qr_code_upload_dir
add_filter('upload_dir', 'zigi_payment_qr_code_upload_dir');

function zigi_payment_qr_code_upload_dir($dirs)
{
    $custom_subdir = '/zigi-payment-qrcode';
    
    $new_path = $dirs['basedir'] . $custom_subdir;
    $new_url  = $dirs['baseurl'] . $custom_subdir;
    
    // Create folder if it doesn't exist
    global $wp_filesystem;
    if (!$wp_filesystem) {
        require_once ABSPATH . '/wp-admin/includes/file.php';
        WP_Filesystem();
    }
    
    if (!$wp_filesystem->is_dir($new_path)) {
        $wp_filesystem->mkdir($new_path);
        $wp_filesystem->put_contents($new_path . '/index.html', '', FS_CHMOD_FILE);
    }
    
    return array_merge($dirs, array(
        'path'   => $new_path,
        'url'    => $new_url,
        'subdir' => $custom_subdir,
    ));
}
This filter is added and removed dynamically during the upload process (lines 169 and 186 in functions.php) to avoid affecting other uploads.

AJAX Hooks

wp_ajax_zigi_payment_qr_code

Handles receipt upload for logged-in users. Type: Action
File: functions.php:200
Function: zigi_payment_qr_code_callback

wp_ajax_nopriv_zigi_payment_qr_code

Handles receipt upload for non-logged-in users (guests). Type: Action
File: functions.php:201
Function: zigi_payment_qr_code_callback
add_action('wp_ajax_zigi_payment_qr_code', 'zigi_payment_qr_code_callback');
add_action('wp_ajax_nopriv_zigi_payment_qr_code', 'zigi_payment_qr_code_callback');

function zigi_payment_qr_code_callback()
{
    // Verify nonce
    $wp_nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : '';
    if (!$wp_nonce || !wp_verify_nonce($wp_nonce, 'zigi_payment_qr_nonce')) {
        wp_send_json_error('Nonce inválido.', 403);
    }
    
    // Validate file upload
    if (!isset($_FILES['files'])) {
        wp_send_json_error('Archivo no recibido.', 400);
    }
    
    // Sanitize file data
    $file = [
        'name'     => sanitize_file_name($_FILES['files']['name']),
        'type'     => sanitize_mime_type($_FILES['files']['type']),
        'tmp_name' => sanitize_text_field($_FILES['files']['tmp_name']),
        'error'    => absint($_FILES['files']['error']),
        'size'     => absint($_FILES['files']['size']),
    ];
    
    // Validate file type
    $check = wp_check_filetype_and_ext($file['tmp_name'], $file['name']);
    $ext = $check['ext'];
    
    if (!in_array($ext, ['jpg', 'jpeg', 'png', 'gif'])) {
        wp_send_json_error('Tipo de archivo inválido.', 400);
    }
    
    // Handle upload with custom directory
    require_once ABSPATH . 'wp-admin/includes/file.php';
    add_filter('upload_dir', 'zigi_payment_qr_code_upload_dir');
    
    $overrides = array(
        'test_form' => false,
        'mimes'     => array(
            'jpg|jpeg' => 'image/jpeg',
            'png'      => 'image/png',
            'gif'      => 'image/gif',
        ),
    );
    
    // Add timestamp to filename
    $file_name = pathinfo($file['name'], PATHINFO_FILENAME);
    $new_filename = sanitize_file_name($file_name . '-' . time() . "." . $ext);
    $file['name'] = $new_filename;
    
    $file_return = wp_handle_upload($file, $overrides);
    
    remove_filter('upload_dir', 'zigi_payment_qr_code_upload_dir');
    
    if (isset($file_return['url'])) {
        wp_send_json_success([
            'message' => 'Archivo subido.',
            'url'     => esc_url_raw($file_return['url'])
        ]);
    } else {
        wp_send_json_error('Falló la carga.', 500);
    }
    
    wp_die();
}
Security Features:
  • Nonce verification for CSRF protection
  • File type validation (only images allowed)
  • File sanitization and validation
  • Secure file naming with timestamps

Order and Meta Box Hooks

add_meta_boxes

Adds a meta box to display the payment receipt on order edit pages. Type: Action
File: functions.php:214
Function: zigi_payment_meta_box
add_action('add_meta_boxes', 'zigi_payment_meta_box');

function zigi_payment_meta_box()
{
    if (defined('WC_VERSION') && version_compare(WC_VERSION, '7.0.0', '>=')) {
        // HPOS compatible
        add_meta_box(
            'zigi-payment-meta-box',
            __('Comprobante de Pago QR', 'paga-con-zigi'),
            'zigi_payment_meta_box_callback',
            'woocommerce_page_wc-orders',
            'normal'
        );
    } else {
        // Legacy post-based orders
        add_meta_box(
            'zigi-payment-meta-box',
            __('Comprobante de Pago QR', 'paga-con-zigi'),
            'zigi_payment_meta_box_callback',
            'shop_order',
            'normal'
        );
    }
}

function zigi_payment_meta_box_callback($post)
{
    $object = $post;
    if (!is_object($post) || !is_a($post, 'WC_Order')) {
        $object = wc_get_order($post->ID);
    }
    
    if ($object) {
        $zigi_payment_qrcode = $object->get_meta('zigi-payment-qrcode', true);
        
        if (!empty($zigi_payment_qrcode) && esc_url($zigi_payment_qrcode)) {
            echo '<a href="' . esc_url($zigi_payment_qrcode) . '" target="_blank">';
            echo '<img src="' . esc_url($zigi_payment_qrcode) . '" alt="Payment Receipt" width="200" height="200" loading="lazy" />';
            echo '</a>';
        }
    }
}

Frontend Display Hooks

Outputs the payment popup HTML in the site footer. Type: Action
File: functions.php:72
Function: zigi_payment_popup
add_action('wp_footer', 'zigi_payment_popup');

function zigi_payment_popup()
{
    $options = get_option('woocommerce_zigi_payment_settings');
    ?>
    <div class="popup-wrapper">
        <span class="helper"></span>
        <div class="popup-main-wrapper">
            <div class="popupCloseButton">&times;</div>
            <div class="first-step" data-price-limit="<?php echo esc_attr($options['limit_amount'] ?? ''); ?>">
                <?php if (!empty($options['preview_qr'])) { ?>
                    <img src="<?php echo esc_url($options['preview_qr']); ?>" class="popup-qr" alt="QR Code" />
                    <span class="price"><?php echo wp_kses_post(WC()->cart->get_cart_total()); ?></span>
                <?php } ?>
            </div>
            <div class="second-step">
                <form method="post" enctype="multipart/form-data" class="box has-advanced-upload">
                    <div class="box__input">
                        <input type="file" name="files" id="file" class="box__file" accept=".png, .jpg, .jpeg, .gif">
                        <label for="file">Drag and drop file to upload</label>
                        <button type="submit" class="box__button">Select File</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <?php
}

Hook Priority Reference

The plugin uses specific priorities to ensure correct execution order:
  • Priority 10 (default): Most hooks run at default priority
  • Priority 11: plugins_loaded - ensures WooCommerce is loaded first
  • Priority 20: Can be used to run after plugin’s main hooks
Lower numbers run earlier, higher numbers run later.

Complete Hook List

Hook NameTypeFileFunctionPriority
woocommerce_payment_gatewaysFilterpaga-con-zigi.php:27zigi_payment_add_gateway_class10
before_woocommerce_initActionpaga-con-zigi.php:39zigi_payment_hpos_compatibility10
plugins_loadedActionpaga-con-zigi.php:52zigi_payment_init_gateway_class11
woocommerce_update_options_payment_gateways_zigi_paymentActionpaga-con-zigi.php:90process_admin_options10
admin_enqueue_scriptsActionfunctions.php:18zigi_payment_admin_script10
wp_footerActionfunctions.php:72zigi_payment_popup10
wp_enqueue_scriptsActionfunctions.php:99zigi_payment_front_script10
upload_dirFilterfunctions.php:169zigi_payment_qr_code_upload_dir10
wp_ajax_zigi_payment_qr_codeActionfunctions.php:200zigi_payment_qr_code_callback10
wp_ajax_nopriv_zigi_payment_qr_codeActionfunctions.php:201zigi_payment_qr_code_callback10
add_meta_boxesActionfunctions.php:214zigi_payment_meta_box10

Next Steps

Customization Guide

Learn how to customize and extend the plugin

Troubleshooting

Common issues and solutions

Build docs developers (and LLMs) love