Back to Tips & Tricks

JetEngine: Show Custom Field for Selected Variation on Product Page

BoostMyCroco TeamPublished on
Product page with variation options, where only the selected variation's custom field details light up in a teal panel

To show a JetEngine custom field for the selected variation, read the field from the variation inside WooCommerce's woocommerce_available_variation filter. Then add it to the data WooCommerce already sends to the variation form. WooCommerce shows those values only for the variation the shopper picks, updates them when the options change, and removes them when the selection is cleared.

A Dynamic Field widget can't do this. It renders once on the server for the parent product, before anyone picks an option. Below are two methods that work with the fields JetEngine already created. Method A is PHP only and prints the fields inside WooCommerce's variation description area. Method B adds a few lines of jQuery so you can place the fields in an Elementor HTML widget on your single product template. Both methods skip empty fields.

Why a Dynamic Field or Listing Grid won't show the selected variation's fields

When you create a meta box with Meta Box for set to WooCommerce Product Variation, the values are saved on each variation, not on the parent product. Three things follow from that:

  • A Dynamic Field with Source Meta Data on the single product template reads the current post, which is the parent product. The variation fields aren't stored there, so you get nothing, or a parent value if a parent field uses the same name.
  • A Listing Grid built on the post type Variations is the method in Crocoblock's guide to variation meta boxes. As the guide says, it displays all variations of the product, not only the selected one.
  • Shoppers pick a variation in the browser without reloading the page. Anything Elementor rendered on the server can't follow that choice.

Don't loop through every variation in the template and hide the extras with CSS. It adds markup for every variation and still needs JavaScript to know which one is selected. WooCommerce's variation form already tracks the selection, so the snippet hooks into that instead.

Step 1: Check your JetEngine variation meta box

  1. Go to JetEngine > Meta Boxes and open your meta box (or click Add New). Under General Settings, Meta Box for must be WooCommerce Product Variation.
  2. Check Position under Visibility Conditions. The options are Options, Pricing, Inventory, Dimensions, Download and Attributes. With Inventory, the fields only appear when the variation's Manage stock? box is ticked. With Download, they only appear when Downloadable is ticked. Options and Attributes are the safe choices, and Attributes puts the fields at the end of the variation panel.
  3. Give every field a unique Name with a prefix, such as var_material, and never reuse a parent product field name. JetEngine 3.8.10 isolates WC variation meta field names to avoid collisions with parent product fields, as listed in Crocoblock's Croco Educates June 2026 newsletter. Update to 3.8.10 or later.
  4. Open Products, edit a Variable product, go to the Variations tab and click a variation. Fill in one field, click Save changes, then click Update. If you skip either button, the values aren't saved.
  5. Before you fill in the rest of your catalog, confirm which meta key your JetEngine version stored, as described below.

Confirm the meta key JetEngine stored

The snippet reads the meta key that matches each field's Name. Because 3.8.10 changed how variation field names are handled, check one variation first. WooCommerce shows the variation ID at the start of each variation's row in the Variations tab (for example #123). Then use one of these:

  • Database: in phpMyAdmin or a similar tool, query the wp_postmeta table (your table prefix may differ):
    SELECT meta_key, meta_value FROM wp_postmeta WHERE post_id = 123;
  • Temporary snippet: add this to functions.php or Code Snippets, load any front-end page while logged in as an administrator, read the list at the bottom, then delete the snippet:
    add_action( 'wp_footer', function () {
        if ( ! current_user_can( 'manage_options' ) ) {
            return;
        }
        $meta = get_post_meta( 123 ); // Replace 123 with your variation ID.
        echo '<pre>' . esc_html( print_r( $meta, true ) ) . '</pre>';
    } );

Find the value you typed. If its key is exactly the field Name (for example var_material), the snippet works as written. If the stored key is different, use the stored key in bmc_variation_jet_field_map() in the next step.

How WooCommerce passes variation data to the page

On a variable product page, WooCommerce builds a data array for each variation with WC_Product_Variable::get_available_variation() and passes it through the woocommerce_available_variation filter with three arguments: the data array, the parent product (WC_Product_Variable) and the variation (WC_Product_Variation). The array holds keys such as variation_id, price_html, sku, availability_html, image and variation_description.

When the shopper completes a selection, WooCommerce's variation script fires the jQuery event found_variation on the form with that variation's data, and shows variation_description under the dropdowns. Method A appends the JetEngine values to variation_description. Method B stores them under a custom key, bmc_fields_html, for a small listener to pick up.

Step 2: Add the PHP snippet

One snippet handles both methods. Edit two things before you save it:

  1. In bmc_variation_jet_field_map(), put your meta keys on the left (the field Names, or the stored keys you found in Step 1 if they differ) and the labels shoppers should see on the right.
  2. In bmc_variation_jet_output_mode(), keep 'description' for Method A, or change it to 'custom' for Method B.

Add this to your child theme's functions.php file, or create a new snippet in the Code Snippets plugin and set it to run on the front end. It has no opening <?php tag because it goes into an existing file:

Code

/**
 * BoostMyCroco: show JetEngine variation meta fields for the selected variation only.
 */

// 1. Meta keys (the field "Name" in the meta box, or the stored key you confirmed) => labels shoppers see.
function bmc_variation_jet_field_map() {
    return array(
        'var_material'       => 'Material',
        'var_finish'         => 'Finish',
        'var_warranty_years' => 'Warranty (years)',
        'var_care'           => 'Care instructions',
    );
}

// 2. Where to output the fields:
// 'description' = Method A (inside WooCommerce's variation description, no JavaScript)
// 'custom'      = Method B (stored in bmc_fields_html for your own container)
function bmc_variation_jet_output_mode() {
    return 'description';
}

// 3. Fields that hold HTML (WYSIWYG). All other fields are printed as plain text.
function bmc_variation_jet_html_fields() {
    return array(
        // 'var_care_notes',
    );
}

add_filter( 'woocommerce_available_variation', 'bmc_variation_jet_fields', 10, 3 );

function bmc_variation_jet_fields( $data, $product, $variation ) {
    if ( ! $variation instanceof WC_Product_Variation ) {
        return $data;
    }

    $html_fields = bmc_variation_jet_html_fields();
    $items       = array();

    foreach ( bmc_variation_jet_field_map() as $key => $label ) {
        // Read from the variation, never from the parent product or global $post.
        $value = $variation->get_meta( $key, true );

        // Skip empty values so empty fields produce no markup.
        if ( '' === $value || null === $value || false === $value || ( is_array( $value ) && empty( $value ) ) ) {
            continue;
        }

        // Arrays and objects (for example checkbox fields) need their own handling.
        if ( is_array( $value ) || is_object( $value ) ) {
            continue;
        }

        if ( in_array( $key, $html_fields, true ) ) {
            $output = wp_kses_post( $value );
        } else {
            $output = nl2br( esc_html( $value ) );
        }

        $items[] = '<li><strong>' . esc_html( $label ) . ':</strong> ' . $output . '</li>';
    }

    // No filled fields for this variation: change nothing.
    if ( empty( $items ) ) {
        return $data;
    }

    $list = '<ul class="bmc-variation-fields">' . implode( '', $items ) . '</ul>';

    if ( 'custom' === bmc_variation_jet_output_mode() ) {
        // Method B: a custom key, read by the jQuery listener.
        $data['bmc_fields_html'] = $list;
    } else {
        // Method A: keep the existing description and append the list.
        $existing                      = isset( $data['variation_description'] ) ? $data['variation_description'] : '';
        $data['variation_description'] = $existing . $list;
    }

    return $data;
}

Method A: Show the fields inside the variation description (PHP only)

With the mode set to 'description', the field list is added after any existing variation description. Text you typed into the variation's Description box still shows above it. To test it:

  1. Open a variable product on the front end and pick a variation that has filled fields. The list should appear under the dropdowns, near the price and stock status.
  2. Switch to a variation with different values. The list should change without a page reload.
  3. Pick a variation with no filled fields. No list should appear. Click Clear, and everything disappears.

Method A needs your add-to-cart template to print WooCommerce's standard variation description area as HTML. If you use Elementor Pro's Add to Cart widget or JetWooBuilder's single add-to-cart widget, test with that widget. If the price updates but no list appears, or the list shows up as raw tags, switch to Method B.

Method B: Show the fields anywhere on your Elementor template (PHP + jQuery)

Use Method B when you want the values somewhere else on the single product template, for example in a specs box next to the gallery.

  1. Change bmc_variation_jet_output_mode() so it returns 'custom'.
  2. In Elementor, edit your single product template, drag an HTML widget to where the fields should appear, and paste this empty container:
    <div id="bmc-variation-fields" hidden></div>
  3. Add this second snippet under the first one, in the same file or Code Snippets snippet:
    add_action( 'wp_enqueue_scripts', 'bmc_variation_jet_fields_script', 20 );
    
    function bmc_variation_jet_fields_script() {
        $js = <<<'JS'
    (function ($) {
        function bmcResetBox() {
            $('#bmc-variation-fields').empty().prop('hidden', true);
        }
    
        // A full selection matched a variation: show its JetEngine fields.
        $(document).on('found_variation', 'form.variations_form', function (event, variation) {
            var $box = $('#bmc-variation-fields');
            if (variation && variation.bmc_fields_html) {
                $box.html(variation.bmc_fields_html).prop('hidden', false);
            } else {
                bmcResetBox();
            }
        });
    
        // Selection cleared or no longer matching a variation: hide the box.
        $(document).on('reset_data hide_variation', 'form.variations_form', bmcResetBox);
    })(jQuery);
    JS;
    
        // Attached to WooCommerce's variation script, so it only prints where that script loads.
        wp_add_inline_script( 'wc-add-to-cart-variation', $js );
    }

wp_add_inline_script() attaches the listener to WooCommerce's wc-add-to-cart-variation script, so it prints only where that script is enqueued. Keep the closing JS; line at the start of its line. The listeners are delegated from document, so they work even if the form is printed after the script. On found_variation, the script inserts the variation's bmc_fields_html and shows the container; if the key is missing, it empties and hides it. Inserting that HTML is safe because PHP already escaped every value. Never build markup in JavaScript from raw meta values.

WooCommerce triggers reset_data on the form when the selection is cleared, incomplete or has no match, and hide_variation on the variation area inside the form, so the delegated listener catches both. To test, pick a variation, then click Clear or set one dropdown back to its empty option. The box should empty and hide.

Hide empty fields and format values safely

  • Empty values (empty string, null, false, empty array) are skipped. A zero stored as 0 still shows, which is what you want for number fields such as warranty years.
  • Text, number and select fields go through esc_html(). Textarea line breaks are kept with nl2br(), which runs after escaping. Select fields return the saved option value, so give options values that read well for shoppers.
  • WYSIWYG fields: add the field's key to bmc_variation_jet_html_fields() so the value goes through wp_kses_post(), which keeps safe formatting and strips scripts.
  • Media fields may store an attachment ID rather than an image. Pass the ID to wp_get_attachment_image() in a separate branch, after checking what your field stores with the Step 1 check.
  • Checkbox fields store an array. The snippet skips arrays, so you won't see a raw "Array" on the page. To show them, add a branch that loops through the checked values and escapes each one.

For styling, target the bmc-variation-fields list class in your theme stylesheet or Elementor's custom CSS.

Troubleshooting

Nothing shows on the product page

Run the meta key check from Step 1 on one saved variation and make sure the keys in bmc_variation_jet_field_map() match what is stored; if they do and you use Method A with a page-builder add-to-cart widget, switch to Method B.

Method B: the box stays empty

View the page source of a variable product (Ctrl+U in most browsers) and search for two things:

  • bmcResetBox: the inline script should be printed next to WooCommerce's add-to-cart-variation script. If it is missing, that script isn't loaded on the page or wasn't registered when the snippet ran, and wp_add_inline_script() did nothing.
  • bmc_fields_html: it should appear in the form's data-product_variations attribute. If it is missing, check that the mode returns 'custom' and that the meta keys are right. On products with many variations this attribute may contain no variation data, because WooCommerce loads each variation on selection; in that case check the response of the get_variation request in your browser's Network tab for bmc_fields_html.

If both are present, confirm the HTML widget contains the container with the id bmc-variation-fields, and that it appears only once on the page.

Values show for the wrong variation or the parent's value

Use the snippet as written, which reads from the variation object, give variation fields a unique prefix, and update JetEngine to 3.8.10 or later.

The fields don't appear in the variation editor

If Position is Inventory or Download, tick Manage stock? or Downloadable on the variation, or change Position to Options or Attributes. Also check the Included for User Roles and Excluded for User Roles visibility conditions.

Some variations never show their fields

WooCommerce leaves out-of-stock variations out of the variation data when its hide out of stock items option (woocommerce_hide_out_of_stock_items) is on. Disabled variations and variations without a price are also left out, unless the woocommerce_hide_invisible_variations filter returns false. Give those variations a price or enable them if they should be selectable.

If you also need product meta inside a form, see how to get meta boxes from a product in JetFormBuilder and use them in a calculated field. For another WooCommerce feature built without an extra plugin, read WooCommerce request a quote without a plugin.

One filter reads the JetEngine fields from the variation, and either WooCommerce's description area or a small listener displays them for the selected option only. If you'd rather have it built and styled for your store, post a request on BoostMyCroco.

Frequently Asked Questions

Does this work with JetWooBuilder single product templates?
The PHP works on WooCommerce's variation data, so it applies to any template that uses WooCommerce's variation form. Method A also needs the standard variation description area to be printed. If your add-to-cart widget doesn't show the list, use Method B with an HTML widget.
Will the variation fields show on shop or category pages?
Not normally, because archive pages don't print the variation form for variable products. If a quick view or swatches plugin loads the variation form elsewhere, the Method A list may appear there too, because it is part of the variation description. Method B only fills the container you placed on the single product template.
Can I still show the parent product's JetEngine fields next to the variation fields?
Yes. Fields from a meta box attached to the parent product work with a normal Dynamic Field widget, because they belong to the product being viewed. They stay visible whatever the shopper selects. Only the variation-level fields need the snippet.
Does adding fields to the variation data slow down the product page?
The snippet adds one meta read per field per variation and a short HTML list only for variations with filled fields. On products with many variations, test page load if you add many fields.

This guide answers a question from our community: Custom meta fields for Woocommerce variations, show on product page only when the relavant varation is choosen

Sources

  1. Attaching Meta Boxes to WooCommerce Product Data and Variations 一 JetEngine (crocoblock.com)
  2. Croco Educates June Issue 2026 - Crocoblock (crocoblock.com)
  3. Custom Meta Box Creation Guide — JetEngine (crocoblock.com)
  4. JetEngine v3.2.0 Beta · Issue #6841 · Crocoblock/suggestions · GitHub (github.com)
  5. WooCommerce Code Reference (woocommerce.github.io)
  6. WooCommerce: Display Selected Variation Info (price, weight, etc.) @ Single Product Page (medium.com)
  7. Add Custom Meta Fields to WooCommerce Variations - www.kathyisawesome.com (kathyisawesome.com)
  8. Вот функция в includes/wc-template-functions.php (qna.habr.com)

Related tips