{"id":19030970,"date":"2026-09-28T08:06:36","date_gmt":"2026-09-28T08:06:36","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/php-test-not-working-as-expected\/"},"modified":"2026-09-28T08:06:36","modified_gmt":"2026-09-28T08:06:36","slug":"php-test-not-working-as-expected","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/php-test-not-working-as-expected\/","title":{"rendered":"PHP test not working as expected"},"content":{"rendered":"<p>Hi,<\/p>\n<p>I&#8217;v just created a PHP test for testing the new (and completely useless) EU GRAN label. It&#8217;s really a great idea to have this gigantic image right under the purchase button.<\/p>\n<p>First, I tried this:<\/p>\n<pre><code>add_action( &#039;woocommerce_review_order_after_submit&#039;, function () {\n\techo &#039;&lt;img src=&quot;&#039; . esc_url( get_stylesheet_directory_uri() . &#039;\/img\/gewaehrleistungslabel_de.svg&#039; ) . &#039;&quot; alt=&quot;EU-Hinweis zur gesetzlichen Gew\u00e4hrleistung&quot; style=&quot;display:block;width:100%;max-width:520px;height:auto;margin-top:2em&quot;&gt;&#039;;\n} );<\/code><\/pre>\n<p>That didn&#8217;t work.<\/p>\n<p>This, on the other hand, did work:<\/p>\n<pre><code>add_action( &#039;woocommerce_after_checkout_form&#039;, function () {\n\t$img = &#039;&lt;img id=&quot;gw-label&quot; src=&quot;&#039; . esc_url( get_stylesheet_directory_uri() . &#039;\/img\/gewaehrleistungslabel_de.svg&#039; ) . &#039;&quot; alt=&quot;EU-Hinweis zur gesetzlichen Gew\u00e4hrleistung&quot; style=&quot;display:block;width:100%;max-width:520px;height:auto;margin-top:2em&quot;&gt;&#039;;\n\n\techo &#039;&lt;script&gt;\n\tjQuery( function ( $ ) {\n\t\tvar img = &#039; . wp_json_encode( $img ) . &#039;;\n\t\tfunction placeLabel() {\n\t\t\tif ( ! $( &quot;#gw-label&quot; ).length ) {\n\t\t\t\t$( &quot;#place_order&quot; ).after( img );\n\t\t\t}\n\t\t}\n\t\t$( document.body ).on( &quot;updated_checkout&quot;, placeLabel );\n\t\tplaceLabel();\n\t} );\n\t&lt;\/script&gt;&#039;;\n} );<\/code><\/pre>\n<p>The problem seems to be that the scope was limited to the checkout page which didn&#8217;t work well with the checkout AJAX:<\/p>\n<pre><code>function is_test_active(): bool {\n  return function_exists( &#039;is_checkout&#039; ) &amp;&amp; is_checkout() &amp;&amp; ! is_wc_endpoint_url( &#039;order-received&#039; ) &amp;&amp; ! is_wc_endpoint_url( &#039;order-pay&#039; );\n}<\/code><\/pre>\n<p>Testing the checkout is a pretty common task. Maybe, you could find a better solution for this.<\/p>\n","protected":false},"template":"","class_list":["post-19030970","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19030970","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19030970\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=19030970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}