Skip to content

Hooks (actions and filters)

Hooks (Actions und Filter) zum Erweitern und Anpassen des Plugin-Verhaltens. Alle verwenden den Namespace polski/.

Filtert die Anzahl der Tage für den Vertragswiderruf.

/**
* @param int $days Number of days for withdrawal (default 14)
*/
apply_filters('polski/withdrawal/days', int $days): int;

Beispiel:

add_filter('polski/withdrawal/days', function (int $days): int {
return 30; // Extend to 30 days
});

Filtert die vom Widerrufsrecht ausgeschlossenen Produktkategorien.

/**
* @param array $categories Array of category IDs
*/
apply_filters('polski/withdrawal/excluded_categories', array $categories): array;

Beispiel:

add_filter('polski/withdrawal/excluded_categories', function (array $categories): array {
$categories[] = 15; // "Digital products" category ID
$categories[] = 22; // "Hygiene products" category ID
return $categories;
});

Filtert die Felder des Widerrufsformulars.

/**
* @param array $fields Array of form fields
*/
apply_filters('polski/withdrawal/form_fields', array $fields): array;

Beispiel:

add_filter('polski/withdrawal/form_fields', function (array $fields): array {
$fields['reason'] = [
'type' => 'textarea',
'label' => 'Withdrawal reason',
'required' => false,
];
return $fields;
});

Action, die nach dem Versand der E-Mail zur Widerrufsbestätigung ausgelöst wird.

/**
* @param int $order_id Order ID
* @param array $form_data Form data
*/
do_action('polski/withdrawal/email_sent', int $order_id, array $form_data): void;

Beispiel:

add_action('polski/withdrawal/email_sent', function (int $order_id, array $form_data): void {
// Log withdrawals to external system
wp_remote_post('https://api.crm.pl/withdrawals', [
'body' => wp_json_encode([
'order_id' => $order_id,
'date' => current_time('mysql'),
]),
]);
}, 10, 2);

Filtert das Anzeigeformat des Grundpreises.

/**
* @param string $format Unit price format
* @param float $unit_price Unit price
* @param string $unit Unit of measurement (kg, l, m, pcs)
* @param int $product_id Product ID
*/
apply_filters('polski/price/unit_format', string $format, float $unit_price, string $unit, int $product_id): string;

Beispiel:

add_filter('polski/price/unit_format', function (string $format, float $unit_price, string $unit, int $product_id): string {
return sprintf('%s / %s', wc_price($unit_price), $unit);
}, 10, 4);

Filtert das neben dem Preis angezeigte MwSt.-Label.

/**
* @param string $label Label text
* @param string $tax_status Product tax status
*/
apply_filters('polski/price/vat_label', string $label, string $tax_status): string;

Beispiel:

add_filter('polski/price/vat_label', function (string $label, string $tax_status): string {
if ($tax_status === 'taxable') {
return 'gross (incl. VAT)';
}
return 'VAT exempt';
}, 10, 2);

Filtert den niedrigsten Preis der letzten 30 Tage (Omnibus-Richtlinie).

/**
* @param float $price Lowest price
* @param int $product_id Product ID
* @param int $days Number of days back
*/
apply_filters('polski/omnibus/lowest_price', float $price, int $product_id, int $days): float;

Beispiel:

add_filter('polski/omnibus/lowest_price', function (float $price, int $product_id, int $days): float {
// Skip products from the "Outlet" category
if (has_term('outlet', 'product_cat', $product_id)) {
return 0.0; // Do not display Omnibus price
}
return $price;
}, 10, 3);

Filtert das Anzeigeformat des Omnibus-Preises.

/**
* @param string $html HTML with price
* @param float $price Lowest price
* @param int $product_id Product ID
*/
apply_filters('polski/omnibus/display_format', string $html, float $price, int $product_id): string;

Beispiel:

add_filter('polski/omnibus/display_format', function (string $html, float $price, int $product_id): string {
return sprintf(
'<small class="omnibus-price">Lowest price from 30 days: %s</small>',
wc_price($price)
);
}, 10, 3);

Action, die nach dem Speichern eines Preises in der Omnibus-Historie ausgelöst wird.

/**
* @param int $product_id Product ID
* @param float $price Saved price
*/
do_action('polski/omnibus/price_recorded', int $product_id, float $price): void;

Filtert die Rechnungsdaten vor dem Versand an KSeF.

/**
* @param array $data Invoice data
* @param WC_Order $order Order object
*/
apply_filters('polski/ksef/invoice_data', array $data, WC_Order $order): array;

Beispiel:

add_filter('polski/ksef/invoice_data', function (array $data, WC_Order $order): array {
$data['additional_info'] = 'Automatically generated invoice';
return $data;
}, 10, 2);

Action, die nach dem erfolgreichen Versand einer Rechnung an KSeF ausgelöst wird.

/**
* @param int $order_id Order ID
* @param string $ksef_id KSeF reference number
* @param array $response KSeF API response
*/
do_action('polski/ksef/invoice_sent', int $order_id, string $ksef_id, array $response): void;

Beispiel:

add_action('polski/ksef/invoice_sent', function (int $order_id, string $ksef_id, array $response): void {
update_post_meta($order_id, '_ksef_reference', $ksef_id);
$order = wc_get_order($order_id);
$order->add_order_note(sprintf('Invoice sent to KSeF: %s', $ksef_id));
}, 10, 3);

Filtert die Formularfelder der DSA-Meldung.

/**
* @param array $fields Form fields
*/
apply_filters('polski/dsa/report_fields', array $fields): array;

Beispiel:

add_filter('polski/dsa/report_fields', function (array $fields): array {
$fields['screenshot'] = [
'type' => 'file',
'label' => 'Screenshot',
'required' => false,
'accept' => '.jpg,.png,.pdf',
];
return $fields;
});

Action, die nach dem Einreichen einer DSA-Meldung ausgelöst wird.

/**
* @param int $report_id Report ID
* @param array $data Report data
*/
do_action('polski/dsa/report_submitted', int $report_id, array $data): void;

Filtert den Inhalt der DOI-Bestätigungs-E-Mail.

/**
* @param string $message Email content
* @param string $email Email address to verify
* @param string $url Verification URL
*/
apply_filters('polski/doi/verification_email', string $message, string $email, string $url): string;

Beispiel:

add_filter('polski/doi/verification_email', function (string $message, string $email, string $url): string {
return sprintf(
'Hello! Confirm your registration by clicking: <a href="%s">Confirm account</a>',
esc_url($url)
);
}, 10, 3);

Action, die nach erfolgreicher DOI-Bestätigung ausgelöst wird.

/**
* @param int $user_id User ID
* @param string $email Email address
*/
do_action('polski/doi/verified', int $user_id, string $email): void;

Filtert die Entscheidung über das Leeren des Plugin-Caches.

/**
* @param bool $should_flush Whether to flush cache
* @param string $group Cache group (omnibus, badges, search)
*/
apply_filters('polski/cache/should_flush', bool $should_flush, string $group): bool;

Beispiel:

add_filter('polski/cache/should_flush', function (bool $should_flush, string $group): bool {
// Do not flush search cache during import
if ($group === 'search' && defined('WP_IMPORTING') && WP_IMPORTING) {
return false;
}
return $should_flush;
}, 10, 2);

Filtert die Cache-Lebensdauer (TTL) in Sekunden.

/**
* @param int $ttl Time in seconds
* @param string $group Cache group
*/
apply_filters('polski/cache/ttl', int $ttl, string $group): int;

Filtert das gerenderte Checkbox-HTML.

/**
* @param string $html Checkbox HTML
* @param array $checkbox Checkbox data
* @param string $location Location (checkout, registration, contact)
*/
apply_filters('polski/checkboxes/render', string $html, array $checkbox, string $location): string;

Action, die nach der Checkbox-Validierung ausgelöst wird.

/**
* @param array $checkboxes Validated checkboxes
* @param bool $valid Validation result
*/
do_action('polski/checkboxes/validated', array $checkboxes, bool $valid): void;

Filtert den Pfad der E-Mail-Vorlage.

/**
* @param string $template Template path
* @param string $type Email type (withdrawal, doi, waitlist)
*/
apply_filters('polski/email/template', string $template, string $type): string;

Beispiel:

add_filter('polski/email/template', function (string $template, string $type): string {
if ($type === 'withdrawal') {
return get_stylesheet_directory() . '/polski/emails/withdrawal.php';
}
return $template;
}, 10, 2);

Filtert die E-Mail-Header.

/**
* @param array $headers Email headers
* @param string $type Email type
*/
apply_filters('polski/email/headers', array $headers, string $type): array;

Filtert die in die Vorlage der Rechtsseite eingefügten Daten.

/**
* @param array $data Template data
* @param string $type Page type (terms, privacy, withdrawal, dsa_report)
*/
apply_filters('polski/legal_page/template_data', array $data, string $type): array;

Beispiel:

add_filter('polski/legal_page/template_data', function (array $data, string $type): array {
if ($type === 'terms') {
$data['delivery_info'] = 'Delivery within 2-5 business days.';
}
return $data;
}, 10, 2);

Action, die nach dem Erstellen einer Rechtsseite ausgelöst wird.

/**
* @param int $page_id Page ID
* @param string $type Page type
*/
do_action('polski/legal_page/generated', int $page_id, string $type): void;
  1. Typen verwenden - deklarieren Sie in Callbacks die Typen von Parametern und Rückgabewerten
  2. Priorität - die Standardpriorität ist 10, verwenden Sie eine höhere (z. B. 20), um das Standardverhalten zu überschreiben
  3. Namespace - erstellen Sie in Ihren Plugins keine Hooks im Namespace polski/, um Konflikte zu vermeiden
  4. Kompatibilität - prüfen Sie vor der Verwendung, ob ein Hook existiert: has_filter('polski/omnibus/lowest_price')
  5. Dokumentation - dokumentieren Sie Ihre Callbacks mit PHPDoc-Kommentaren

Probleme melden: github.com/wppoland/polski/issues

Diese Seite dient ausschließlich Informationszwecken und stellt keine Rechtsberatung dar. Konsultieren Sie vor der Umsetzung einen Anwalt. Polski for WooCommerce ist Open-Source-Software (GPLv2), die ohne Gewährleistung bereitgestellt wird.