# ShopGlut PDF Invoices - Pro Plugin Extension Hooks

This document lists all available hooks and filters that pro plugins can use to extend the functionality of the free ShopGlut PDF Invoices plugin.

## Pro Feature Detection

### Core Pro Manager Integration
- **Class**: `ShopGlutPdfInvoicesProManager`
- **Method**: `is_pro_active()` - Check if pro version is active
- **Method**: `is_pro_feature_available($feature)` - Check if specific feature is available
- **Method**: `get_pro_feature($feature, $default)` - Get pro feature value with fallback

### Pro Detection Filters
```php
// Override pro detection
add_filter('shopglut_pdf_invoices_is_pro_active', function($is_pro) {
    return your_pro_detection_logic();
});

// Final pro detection filter
add_filter('shopglut_pdf_invoices_pro_detected', function($is_pro) {
    return $is_pro || your_additional_checks();
});

// License validation
add_filter('shopglut_pdf_invoices_validate_license', function($is_valid, $license_key) {
    return validate_your_license($license_key);
}, 10, 2);
```

## Document Generation Hooks

### Invoice Generation
```php
// Override invoice template selection
add_filter('shopglut_pdf_invoices_pro_template_override', function($template, $document_type, $order_id) {
    if ($document_type === 'invoice') {
        return 'your_pro_template';
    }
    return $template;
}, 10, 3);

// Modify invoice content before generation
add_filter('shopglut_pdf_invoices_pro_invoice_content', function($content, $order_id, $template) {
    // Modify $content array
    return $content;
}, 10, 3);
```

### UBL Invoice Generation
```php
// Override UBL format
add_filter('shopglut_pdf_invoices_pro_ubl_format_override', function($format, $order_id) {
    return 'your_pro_format'; // e.g., 'peppol_bis', 'factur_x', 'zugferd'
}, 10, 2);

// Add custom UBL content
add_filter('shopglut_pdf_invoices_pro_ubl_content', function($xml_content, $order_id, $format) {
    // Modify XML content
    return $xml_content;
}, 10, 3);
```

### Template System
```php
// Add pro templates
add_filter('shopglut_pdf_invoices_pro_templates', function($templates, $document_type) {
    $templates['premium_template'] = __('Premium Template', 'your-domain');
    return $templates;
}, 10, 2);

// Override template path
add_filter('shopglut_pdf_invoices_pro_template_path', function($path, $template, $document_type) {
    if ($template === 'premium_template') {
        return '/path/to/your/template.php';
    }
    return $path;
}, 10, 3);
```

## Email Attachment System

### Email Attachment Extensions
```php
// Handle pro email attachments
add_filter('shopglut_pdf_invoices_pro_email_attachments', function($attachments, $email_id, $order, $original_attachments, $settings) {
    // Add your pro logic for email attachments
    if (in_array($email_id, ['customer_processing', 'customer_completed'])) {
        // Add credit notes, shipping labels, etc.
    }
    return $attachments;
}, 10, 5);

// Add supported pro email types
add_filter('shopglut_pdf_invoices_pro_email_attachments', function($types) {
    $types['customer_processing'] = __('Customer Processing Emails', 'your-domain');
    $types['customer_completed'] = __('Customer Completed Emails', 'your-domain');
    return $types;
});
```

## Advanced Features Extensions

### Bulk Actions
```php
// Add pro bulk actions
add_filter('shopglut_pdf_invoices_pro_bulk_actions', function($actions, $pro_manager, $settings) {
    if ($pro_manager->is_pro_active()) {
        $actions['download_credit_notes'] = __('Download Credit Notes', 'your-domain');
        $actions['download_shipping_labels'] = __('Download Shipping Labels', 'your-domain');
    }
    return $actions;
}, 10, 3);

// Handle pro bulk actions
add_filter('shopglut_pdf_invoices_handle_pro_bulk_action', function($handled, $action, $post_ids, $pro_manager) {
    if ($action === 'download_credit_notes') {
        your_bulk_credit_notes_handler($post_ids);
        return true;
    }
    return $handled;
}, 10, 4);

// Generate pro documents for bulk
add_filter('shopglut_pdf_invoices_pro_bulk_document', function($file_path, $order_id, $document_type, $pro_manager) {
    if ($document_type === 'credit_note') {
        return your_credit_note_generator($order_id);
    }
    return $file_path;
}, 10, 4);
```

### Order Actions
```php
// Add pro order actions in meta box
add_filter('shopglut_pdf_invoices_pro_order_actions', function($actions, $order_id, $pro_manager, $settings) {
    $actions[] = '<a href="' . your_credit_note_url($order_id) . '" class="button">Credit Note</a>';
    return $actions;
}, 10, 4);

// Add custom meta box content
add_action('shopglut_pdf_invoices_pro_order_meta_content', function($order_id, $pro_manager, $settings) {
    echo '<div class="pro-features">';
    echo '<h4>Pro Features</h4>';
    // Your pro content
    echo '</div>';
}, 10, 3);
```

## Document Types & Formats

### Document Types
```php
// Add pro document types
add_filter('shopglut_pdf_invoices_pro_document_types', function($types) {
    $types['credit_note'] = __('Credit Note', 'your-domain');
    $types['shipping_label'] = __('Shipping Label', 'your-domain');
    $types['delivery_note'] = __('Delivery Note', 'your-domain');
    return $types;
});
```

### UBL Formats
```php
// Add pro UBL formats
add_filter('shopglut_pdf_invoices_pro_ubl_formats', function($formats) {
    $formats['peppol_bis'] = __('PEPPOL BIS', 'your-domain');
    $formats['factur_x'] = __('Factur-X', 'your-domain');
    $formats['zugferd'] = __('ZUGFeRD', 'your-domain');
    return $formats;
});
```

## System Integration

### AJAX Handlers
```php
// Register pro AJAX handlers
add_action('shopglut_pdf_invoices_register_ajax_handlers', function($pro_manager) {
    if ($pro_manager->is_pro_active()) {
        add_action('wp_ajax_generate_credit_note', 'your_credit_note_handler');
        add_action('wp_ajax_generate_shipping_label', 'your_shipping_label_handler');
    }
});
```

### WooCommerce Integration
```php
// Pro WooCommerce integration
add_action('shopglut_pdf_invoices_woocommerce_integration', function($pro_manager, $init_instance) {
    if ($pro_manager->is_pro_active()) {
        // Add your WooCommerce hooks
        add_filter('woocommerce_my_account_my_orders_actions', 'your_my_account_actions');
    }
}, 10, 2);
```

### Cleanup System
```php
// Add pro directories for cleanup
add_filter('shopglut_pdf_invoices_pro_cleanup_directories', function($directories, $pro_manager) {
    $upload_dir = wp_upload_dir();
    $directories[] = $upload_dir['basedir'] . '/shopglut-credit-notes/';
    $directories[] = $upload_dir['basedir'] . '/shopglut-shipping-labels/';
    return $directories;
}, 10, 2);
```

## Feature Management

### Feature Availability
```php
// Control feature availability
add_filter('shopglut_pdf_invoices_pro_feature_available', function($available, $feature) {
    // Check license, subscription, etc.
    return your_feature_check($feature);
}, 10, 2);

// Get feature values
add_filter('shopglut_pdf_invoices_pro_feature_advanced_templates', function($default) {
    return get_option('your_pro_templates_setting', $default);
});
```

### Currency Support
```php
// Add pro currency symbols
add_filter('shopglut_pdf_invoices_pro_currency_symbol', function($symbol, $currency) {
    $pro_symbols = [
        'CUSTOM1' => '¤',
        'CUSTOM2' => '⚡',
    ];
    return isset($pro_symbols[$currency]) ? $pro_symbols[$currency] : $symbol;
}, 10, 2);
```

## Initialization Hooks

### Plugin Initialization
```php
// Initialize pro features after main plugin init
add_action('shopglut_pdf_invoices_after_init', function($init_instance) {
    // Access to all managers through $init_instance
    $pro_manager = $init_instance->get_pro_manager();
    if ($pro_manager->is_pro_active()) {
        // Initialize your pro features
    }
});

// Register pro features (always runs)
add_action('shopglut_pdf_invoices_register_pro_features', function() {
    // Register your pro features even if not active
    // This helps with discovery and upsells
});

// Initialize pro features (only when active)
add_action('shopglut_pdf_invoices_init_pro_features', function() {
    // Only runs when pro is active
});
```

## Usage Examples

### Complete Pro Plugin Integration
```php
class YourProPlugin {
    public function __construct() {
        add_action('plugins_loaded', array($this, 'init'), 20);
    }
    
    public function init() {
        // Define pro constant
        define('SHOPGLUT_PDF_INVOICES_PRO', true);
        
        // Hook into the system
        add_action('shopglut_pdf_invoices_register_pro_features', array($this, 'register_features'));
        add_action('shopglut_pdf_invoices_init_pro_features', array($this, 'init_features'));
    }
    
    public function register_features() {
        // Register what your pro version offers
        add_filter('shopglut_pdf_invoices_pro_document_types', array($this, 'add_document_types'));
        add_filter('shopglut_pdf_invoices_pro_templates', array($this, 'add_templates'), 10, 2);
    }
    
    public function init_features() {
        // Initialize active pro features
        add_filter('shopglut_pdf_invoices_pro_email_attachments', array($this, 'handle_email_attachments'), 10, 5);
    }
}

new YourProPlugin();
```

This comprehensive hook system allows pro plugins to extend every aspect of the free plugin while maintaining clean separation and backwards compatibility.