WPIntell

Source evidence

How to AB test advanced custom field

Nelio A/B Testing – AB Tests and Heatmaps for Better Conversion Optimization · support · 2026-04-30T10:18:00+00:00

mixedsentiment
mediumseverity
0.85relevance
7replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

3 / 28 rows with source links

10.7% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

25 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
cutu234 resolved
I would like to test two versions of a page hero section on Woo category pages. I use an advanced custom field for the content that is rendered like so: function archive_header() { if (is_product_category()) { $cat = get_queried_object(); $custom_field = get_field('product_category_header', $cat); echo '<div class="fullwidth-banner cat-banner">' . $custom_field . '</div>'; do_action('woo_cat_rating', $cat); if (in_array($cat->slug, array('schimmelentferner', 'spruehgeraete'))) { echo '<p style="text-align: center;"><a class="button scroll-element" id="video" href="#produktvideo">Anwendungsvideo</a></p>'; } } } add_action('woocommerce_before_shop_loop', 'archive_header', 10); I could put the content in the function and use a PHP test. Can I somehow run a test by just changing the content of the custom field (WYSIWYG-Editor)? That would be much easier. Thank you. This topic was modified 1 month, 1 week ago by cutu234 . You’d still need a PHP test to change the value of the field, right? That’s exactly where I’m struggling. I’m not sure whether it would even be possible to create a test that changes the content of the custom field. I tried the custom post type test, but the custom fields are not available in the drop down. Just to clarify the setup: I created a custom field (full editor) for Woocommerce categories. This is on the ACF side. My snippets provides the rendering on the category page. I’m not sure whether it would even be possible to create a test that changes the content of the custom field. I tried the custom post type test, but the custom fields are not available in the drop down. Yeah, no, I don’t think that’d be possible with the current set of tests. You’ll have to create a PHP test whether you like it or not. I think the only solution would be to create a PHP test that somehow looks something similar to this: // Unhook original hero section: remove_action('woocommerce_before_shop_loop', 'archive_header', 10); // Create new hero section: function archive_header_b() { if ( ! is_product_category() ) { return; } $cat = get_queried_object(); // Load different field: $custom_field = get_field( 'product_category_header_b', $cat ); echo '<div class="fullwidth-banner cat-banner">' . $custom_field . '</div>'; do_action( 'woo_cat_rating', $cat ); if (in_array($cat->slug, array('schimmelentferner', 'spruehgeraete'))) { echo '<p style="text-align: center;"><a class="button scroll-element" id="video" href="#produktvideo">Anwendungsvideo</a></p>'; } } add_action('woocommerce_before_shop_loop', 'archive_header', 10); and that’ll probably do the trick. Hi David, don’t get me wrong: I absolutely love the PHP test feature. I just wanted to make sure that this would be the right approach. Now, I have a problem. I can’t save the following snippet for the variant. Not sure why: remove_action('woocommerce_before_shop_loop', 'archive_header', 10); function archive_header() { if (is_product_category()) { $cat = get_queried_object(); if ($cat->slug == 'gruenbelagentferner') { $custom_field = get_field('banner_fur_ab-test_quart', $cat); } else { $custom_field = get_field('product_category_header', $cat); } echo '<div class="fullwidth-banner cat-banner">' . $custom_field . '</div>'; do_action('woo_cat_rating', $cat); if (in_array($cat->slug, array('schimmelentferner', 'spruehgeraete'))) { echo '<p style="text-align: center;"><a class="button scroll-element" id="video" href="#produktvideo">Anwendungsvideo</a></p>'; } } } add_action('woocommerce_before_shop_loop', 'archive_header', 10); “Save and Preview” simply removes the snippet. What am I missing? In addition to that: The test scope would be return is_product_category('gruenbelagentferner'); , right? This reply was modified 1 month ago by cutu234 . This reply was modified 1 month ago by cutu234 . I guess the problem is you’re defining a function ( archive_header ) that already exists in the global scope, which triggers an error. Rename your alternative function to something else: remove_action( 'woocommerce_before_shop_loop', 'archive_header' ); function archive_header_b_variant() { … } add_action( 'woocommerce_before_shop_loop', 'archive_header_b_variant' ); This reply was modified 1 month ago by David Aguilera . Spot on, David. Should have thought of this myself. 🙂 Works just fine. Thanks, Mike Glad I could help!

Comments

7 shown
David Aguilera 2026-04-30T11:02:00+00:00

You’d still need a PHP test to change the value of the field, right?

cutu234 2026-04-30T12:32:00+00:00

That’s exactly where I’m struggling. I’m not sure whether it would even be possible to create a test that changes the content of the custom field. I tried the custom post type test, but the custom fields are not available in the drop down. Just to clarify the setup: I created a custom field (full editor) for Woocommerce categories. This is on the ACF side. My snippets provides the rendering on the category page.

David Aguilera 2026-04-30T13:08:00+00:00

I’m not sure whether it would even be possible to create a test that changes the content of the custom field. I tried the custom post type test, but the custom fields are not available in the drop down. Yeah, no, I don’t think that’d be possible with the current set of tests. You’ll have to create a PHP test whether you like it or not. I think the only solution would be to create a PHP test that somehow looks something similar to this: // Unhook original hero section: remove_action('woocommerce_before_shop_loop', 'archive_header', 10); // Create new hero section: function archive_header_b() { if ( ! is_product_category() ) { return; } $cat = get_queried_object(); // Load different field: $custom_field = get_field( 'product_category_header_b', $cat ); echo '<div class="fullwidth-banner cat-banner">' . $custom_field . '</div>'; do_action( 'woo_cat_rating', $cat ); if (in_array($cat->slug, array('schimmelentferner', 'spruehgeraete'))) { echo '<p style="text-align: center;"><a class="button scroll-element" id="video" href="#produktvideo">Anwendungsvideo</a></p>'; } } add_action('woocommerce_before_shop_loop', 'archive_header', 10); and that’ll probably do the trick.

cutu234 2026-05-11T10:48:00+00:00

Hi David, don’t get me wrong: I absolutely love the PHP test feature. I just wanted to make sure that this would be the right approach. Now, I have a problem. I can’t save the following snippet for the variant. Not sure why: remove_action('woocommerce_before_shop_loop', 'archive_header', 10); function archive_header() { if (is_product_category()) { $cat = get_queried_object(); if ($cat->slug == 'gruenbelagentferner') { $custom_field = get_field('banner_fur_ab-test_quart', $cat); } else { $custom_field = get_field('product_category_header', $cat); } echo '<div class="fullwidth-banner cat-banner">' . $custom_field . '</div>'; do_action('woo_cat_rating', $cat); if (in_array($cat->slug, array('schimmelentferner', 'spruehgeraete'))) { echo '<p style="text-align: center;"><a class="button scroll-element" id="video" href="#produktvideo">Anwendungsvideo</a></p>'; } } } add_action('woocommerce_before_shop_loop', 'archive_header', 10); “Save and Preview” simply removes the snippet. What am I missing? In addition to that: The test scope would be return is_product_category('gruenbelagentferner'); , right? This reply was modified 1 month ago by cutu234 . This reply was modified 1 month ago by cutu234 .

David Aguilera 2026-05-11T11:05:00+00:00

I guess the problem is you’re defining a function ( archive_header ) that already exists in the global scope, which triggers an error. Rename your alternative function to something else: remove_action( 'woocommerce_before_shop_loop', 'archive_header' ); function archive_header_b_variant() { … } add_action( 'woocommerce_before_shop_loop', 'archive_header_b_variant' ); This reply was modified 1 month ago by David Aguilera .

cutu234 2026-05-11T14:33:00+00:00

Spot on, David. Should have thought of this myself. 🙂 Works just fine. Thanks, Mike

David Aguilera 2026-05-11T15:15:00+00:00

Glad I could help!