View Categories

EAN Barcode Generator: Developer Hooks and Filters Reference

Developer hooks and filters reference #

EAN for WooCommerce exposes filters, actions, and shortcodes so you can adjust how EANs are generated, validated, displayed, searched, and exported without editing plugin files. Every hook name below is taken directly from the version 5.5.9 source. All hooks use the alg_wc_ean_* prefix.

The settings these hooks relate to live under WPFactory > EAN (also reachable at WooCommerce > Settings > EAN). EAN is stored in product meta under the key set by Advanced > Meta key (option alg_wc_ean_meta_key, default _alg_ean).

Value filters #

These filters fire on a value the plugin is about to use or output, so whatever your callback returns wins.

Filter Filtered value Arguments
alg_wc_ean_get_type The EAN type used for validation and barcodes $type, $raw_type, $ean, $product_id
alg_wc_ean_is_valid Whether an EAN passes the check-digit validation $result, $value, $type
alg_wc_ean_display The EAN HTML rendered on product and shop pages $output_html, $value, $style, $template, $single_or_loop
alg_wc_ean_display_cart The EAN HTML rendered in the cart $output_html, $ean, $template
alg_wc_ean_shortcode_output The output of every plugin shortcode $sanitized_result, $result, $atts
alg_wc_ean_input_pattern The input pattern attribute on the admin EAN field $result, $atts, $type
alg_wc_ean_input_custom_atts Custom attributes on the admin EAN input $result, $product_id, $atts
alg_wc_ean_edit Whether the admin EAN edit field is registered $enabled

Force a specific EAN type for one product #

add_filter( 'alg_wc_ean_get_type', function ( $type, $raw_type, $ean, $product_id ) {
    if ( 1234 === (int) $product_id ) {
        $type = 'UPCA';
    }
    return $type;
}, 10, 4 );

Structured data filters #

These control the EAN that is added to product structured data (for Google Search Console and similar).

  • alg_wc_ean_product_structured_data_value – arguments $value, $product: the EAN value placed in structured data.
  • alg_wc_ean_product_structured_data_markup_key – arguments $key, $type, $product: the key used, for example gtin13 or a custom key.
  • alg_wc_ean_product_structured_data_markup_value – arguments $value, $product: the markup value.
  • alg_wc_ean_product_structured_data_allow_empty_value – arguments $allow, $product: return true to output the key even when the EAN is empty.

Generate-tool filters #

These fire inside the Generate product tool, so you can control how new EANs are built.

Filter Filtered value Arguments
alg_wc_ean_product_tools_generate_ean_country_prefix The country (GS1) prefix used when generating $prefix, $product_id
alg_wc_ean_product_tools_generate_ean_seed_prefix The seed prefix (manufacturer code) $seed_prefix, $product_id
alg_wc_ean_product_tools_generate_ean_seed The seed (product code) used to generate $seed, $product_id
alg_wc_ean_tool_product_assign_list_reuse_deleted Whether a deleted product’s EAN is returned to the assign list $reuse, $post_id, $ean

Search filters #

The plugin adds EAN to product and order search. Return false from either filter to skip the plugin’s search handling in a given query.

  • alg_wc_ean_search_backend – arguments $enabled, $query, $key: admin-side product search.
  • alg_wc_ean_search – arguments $enabled, $wp_query, $key: frontend product search.

REST API filters #

  • alg_wc_ean_rest_api_product_ean_key – arguments $key, $response, $product, $request: the JSON key EAN is added under in product responses (default ean).
  • alg_wc_ean_rest_api_order_ean_key – arguments $key, $response, $order, $request: the JSON key for order responses (default ean).

The settings gate filter #

alg_wc_ean_settings is how the plugin decides whether a Pro-only field is disabled. In the free version it returns array( 'disabled' => 'disabled' ), which disables the field; in Pro it returns '', removing the attribute. It gates the enable checkboxes for the Barcodes, 2D Barcodes, Print, and Extra Fields sections. It is an internal gate, not intended for store customization.

Barcode and print filters (Pro) #

These fire only when the Pro barcode and print features are active.

Filter Filtered value Arguments
alg_wc_ean_barcode_args Arguments passed to the barcode generator $args, $dim
alg_wc_ean_barcode_shortcode_content The value encoded by the 1D barcode shortcode $value, $product_id, $atts
alg_wc_ean_barcode_2d_shortcode_content The value encoded by the 2D barcode shortcode $value, $product_id, $atts
alg_wc_ean_print_barcodes_to_pdf_template The label template for the PDF print tool $template, $product_id, $ean, $product, $options
alg_wc_ean_print_get_products The product list sent to the PDF print tool $product_eans
alg_wc_ean_print_barcodes_to_pdf_general_settings The Print section general settings array $settings, $options

The print feature also exposes alg_wc_ean_print_barcodes_to_pdf_default_settings, alg_wc_ean_print_barcodes_to_pdf_template_settings_desc, alg_wc_ean_print_barcode_shop_order_refunded_item_qty, and alg_wc_ean_print_render_meta_box_shop_order_force_refunded.

Other filters #

  • alg_wc_ean_settings_page_label – the label of the settings tab and the WPFactory submenu item (default EAN).
  • alg_wc_ean_product_function_shortcode_user_capability – the capability required to run [alg_wc_ean_product_function] (default manage_woocommerce).

Actions #

Action Fires when Arguments
alg_wc_ean_core_loaded The plugin core has finished loading its classes $core
alg_wc_ean_settings_saved A settings section is saved (drives export, import, and reset) $current_section

Shortcodes #

The free version registers these shortcodes. They share common attributes: product_id, before, after, on_empty, and (where relevant) parent.

Shortcode Returns Free/Pro
[alg_wc_ean] The product’s EAN Free
[alg_wc_ean_is_valid] Valid / Invalid EAN label Free
[alg_wc_ean_is_unique] Unique / Duplicated EAN label Free
[alg_wc_ean_product_attr] A product attribute (attr) Free
[alg_wc_ean_product_image] The product image (output, size) Free
[alg_wc_ean_product_name] The product name or title (type) Free
[alg_wc_ean_product_sku] The product SKU Free
[alg_wc_ean_product_price] The product price (type, raw) Free
[alg_wc_ean_product_id] The product ID Free
[alg_wc_ean_product_author_id] The product author ID (min_length) Free
[alg_wc_ean_product_meta] A product meta value (key) Free
[alg_wc_ean_product_function] A WC_Product method result (name) Free
[alg_wc_ean_product_terms] Product terms (taxonomy, return) Free
[alg_wc_ean_if] Conditional content (value1, operator, value2, then, else) Free
[alg_wc_ean_if_product_cat] Content if the product is in a category (in, not_in) Free
[alg_wc_ean_if_product_tag] Content if the product has a tag (in, not_in) Free
[alg_wc_ean_barcode] A 1D barcode image (content, w, h) Pro
[alg_wc_ean_barcode_2d] A 2D barcode or QR code image Pro
[alg_wc_ean_barcode_base64] A 1D barcode as a base64 string Pro
[alg_wc_ean_barcode_2d_base64] A 2D barcode as a base64 string Pro

Read a product’s EAN in code #

$ean = get_post_meta( $product_id, '_alg_ean', true );

// Or through the plugin's core helper (respects a custom meta key):
$ean = wpfactory_wc_ean()->core->get_ean( $product_id );

If you changed Advanced > Meta key, read the option first: get_option( 'alg_wc_ean_meta_key', '_alg_ean' ).

Need help? #

If you are extending EAN for WooCommerce and a hook does not behave as expected, contact our team on the EAN for WooCommerce support forum with the hook name and a short code sample.