Contents
On this page
Hooks reference - Plugixa Extra Product Options
Plugixa Extra Product Options has WordPress actions and filters for themes and other plugins.
Every hook starts with plugixa_epo_. Add your code to a small plugin or to your child theme’s
functions.php.
Hooks marked Pro only run when Pro is active.
Groups
| Hook | Type | Arguments | Use |
|---|---|---|---|
plugixa_epo_group_published |
action | int $id, array $doc |
A group was published. $doc is the published document. |
plugixa_epo_group_deleted |
action | int $id |
A group was deleted: drop whatever you keep for it. |
plugixa_epo_publish_problems |
filter | array $problems, array $doc |
Add your own checks before publishing. Each problem is ['field' => $field_id, 'message' => $text]. |
plugixa_epo_groups_for_product |
filter | array $groups, WC_Product $product |
The published groups of a product, before they are cached. |
plugixa_epo_visitor_groups |
filter | array $groups, WC_Product $product |
The groups a shopper gets for a product, after the cache. Adjust them for this visitor or this moment. |
plugixa_epo_group_applies |
filter | bool $applies, array $group, WC_Product $product |
Return false to hide a group from the current shopper. |
The groups a product shows are cached. Use plugixa_epo_visitor_groups or
plugixa_epo_group_applies for anything that depends on the visitor, never
plugixa_epo_groups_for_product.
Prices
| Hook | Type | Arguments | Use |
|---|---|---|---|
plugixa_epo_base_price |
filter | float $price, WC_Product $product |
The product price options are added to, and percentages are worked out on. |
plugixa_epo_options_total |
filter | float $total, WC_Product $product, array $values |
The options’ total for one item, before it is added to the product price. |
plugixa_epo_price_types |
filter | string[] $types |
Register a price type of your own. |
plugixa_epo_field_price |
filter | float $amount, array $field, mixed $value, float $base_price, array $values, ?array $doc |
Price a field that uses your price type. |
plugixa_epo_price_unit |
filter | string $unit, string $price_type |
Words after the amount beside an option of your price type, such as “per character”. |
Prices are always worked out on the server. A price you change in the browser only changes what the page shows: change it in PHP so the cart charges it.
Example: 10% off every option for members
add_filter( 'plugixa_epo_options_total', function ( $total, $product, $values ) {
if ( is_user_logged_in() && $total > 0 ) {
$total = round( $total * 0.9, wc_get_price_decimals() );
}
return $total;
}, 10, 3 );
This filter changes what the cart charges. The live total on the product page still shows the full option prices, so tell members about the discount on the page.
Validation
| Hook | Type | Arguments | Use |
|---|---|---|---|
plugixa_epo_group_errors |
filter | array $errors, array $doc, array $values |
Checks that need several answers at once, run once every field passed on its own. Return errors keyed by field id. |
plugixa_epo_field_error |
filter | ?string $error, array $field, mixed $value |
Check a value of a field type an extension added. Return a message to refuse it. |
plugixa_epo_invalid_message |
filter | ?string $message, array $field, string $label |
The message shown when a value of an extension’s field type is refused. |
plugixa_epo_rule_context |
filter | array $context, $quantity, $variation_id |
Values rules may test, keyed with @, such as @quantity and @variation. |
Example: the delivery date must be at least two days ahead
add_filter( 'plugixa_epo_group_errors', function ( $errors, $doc, $values ) {
$earliest = wp_date( 'Y-m-d', strtotime( '+2 days' ) ); // Dates are Y-m-d.
foreach ( $doc['fields'] as $field ) {
if ( 'date' === $field['type'] && ! empty( $values[ $field['id'] ] )
&& $values[ $field['id'] ] < $earliest ) {
$errors[ $field['id'] ] = sprintf( '%s must be at least two days from today.', $field['label'] );
}
}
return $errors;
}, 10, 3 );
Product page
| Hook | Type | Arguments | Use |
|---|---|---|---|
plugixa_epo_form_values |
filter | array $values, WC_Product $product |
Values to fill the form with instead of the fields’ defaults (group id => field id => value). |
plugixa_epo_setting_text |
filter | string $value, string $key |
The Title above the options (options_label) or the Total label (totals_label) as the visitor reads it. |
plugixa_epo_price_hint_before |
filter | string $html, array $item, float $base_price, float $ratio |
Markup just before an option’s price, such as an earlier price struck through. |
plugixa_epo_render_field |
filter | ?string $html, array $field, array $context |
The control of a field type an extension added. |
plugixa_epo_render_choices |
filter | ?string $html, array $field, array $context |
Replace the markup of a radio or checkbox group. Inputs must keep their name and option ids. |
plugixa_epo_storefront_deps |
filter | string[] $deps, array $docs |
Scripts the options script needs loaded first. |
plugixa_epo_storefront_enqueued |
action | string $handle, array $docs |
The form is on this page and its assets are enqueued: add yours. |
Markup returned by the render filters goes through the plugin’s own wp_kses() allow-list.
Cart and order
| Hook | Type | Arguments | Use |
|---|---|---|---|
plugixa_epo_readable_row |
filter | array $row, array $field, mixed $value |
One label: answer row in the cart, on the order and in emails. Return null to leave it out, or set 'private' => true for staff only. |
plugixa_epo_display_value |
filter | string $text, array $field, mixed $value |
How a value of an extension’s field type reads as text. |
plugixa_epo_order_item_options_changed |
action | WC_Order_Item_Product $item, array $old, array $new |
Pro. A shop manager changed an order line’s options. |
plugixa_epo_order_edit_groups |
filter | array $groups, WC_Order_Item_Product $item |
Pro. The groups an order line is edited with. |
plugixa_epo_context_user |
filter | WP_User $user |
Pro. Whose role rules and role discounts use: the visitor, or the order’s customer when editing an order. |
Example: hide a field from the customer’s emails
add_filter( 'plugixa_epo_readable_row', function ( $row, $field ) {
if ( 'Internal reference' === $field['label'] ) {
$row['private'] = true; // Shown on the order screen, not to the customer.
}
return $row;
}, 10, 2 );
Field types
| Hook | Type | Arguments | Use |
|---|---|---|---|
plugixa_epo_field_types |
filter | string[] $types |
Register a field type. |
plugixa_epo_numeric_types |
filter | string[] $types |
Field types whose value is a number, so min/max checks and number rules apply. |
plugixa_epo_type_price |
filter | ?float $amount, array $field, mixed $value, float $base_price, int $decimals |
A field type that prices itself, such as a sum over repeated rows. |
A new field type also needs its editor and its product page script. Most stores never need one: ask us first, Pro may already cover it.
Targeting
| Hook | Type | Arguments | Use |
|---|---|---|---|
plugixa_epo_target_rows |
filter | array $rows, array $targets |
Extra target rows, as [type, id] pairs, matched against the product’s terms. |
plugixa_epo_product_terms |
filter | array $terms, WC_Product $product |
A product’s term ids by target type, which target rows are matched against. |
Settings, privacy and uninstall
| Hook | Type | Arguments | Use |
|---|---|---|---|
plugixa_epo_settings_defaults |
filter | array $defaults |
The settings’ default values. |
plugixa_epo_settings_sanitized |
filter | array $settings |
The settings about to be saved, already sanitized. |
plugixa_epo_privacy_policy_text |
filter | string $html |
The suggested privacy policy paragraphs. |
plugixa_epo_uninstall_tables |
filter | string[] $tables |
The plugin tables dropped on uninstall, when erasing is on. |
plugixa_epo_uninstall_options |
filter | string[] $options |
Extra options deleted on uninstall. Only names starting with plugixa_epo_ are deleted. |
Lifecycle
| Hook | Type | Arguments | Use |
|---|---|---|---|
plugixa_epo_loaded |
action | $container |
The plugin has booted. |
plugixa_epo_activated |
action | The plugin was activated. | |
plugixa_epo_deactivated |
action | The plugin was deactivated. | |
plugixa_epo_register_rest_routes |
action | string $namespace, $container |
Register your own REST routes under plugixa-epo/v1. |
Related
- Manage groups and settings from outside WordPress with the REST API.
Quick Links
Share