PHP test not working as expected
-
Hi,
I’v just created a PHP test for testing the new (and completely useless) EU GRAN label. It’s really a great idea to have this gigantic image right under the purchase button.
First, I tried this:
add_action( 'woocommerce_review_order_after_submit', function () { echo '<img src="' . esc_url( get_stylesheet_directory_uri() . '/img/gewaehrleistungslabel_de.svg' ) . '" alt="EU-Hinweis zur gesetzlichen Gewährleistung" style="display:block;width:100%;max-width:520px;height:auto;margin-top:2em">'; } );That didn’t work.
This, on the other hand, did work:
add_action( 'woocommerce_after_checkout_form', function () { $img = '<img id="gw-label" src="' . esc_url( get_stylesheet_directory_uri() . '/img/gewaehrleistungslabel_de.svg' ) . '" alt="EU-Hinweis zur gesetzlichen Gewährleistung" style="display:block;width:100%;max-width:520px;height:auto;margin-top:2em">'; echo '<script> jQuery( function ( $ ) { var img = ' . wp_json_encode( $img ) . '; function placeLabel() { if ( ! $( "#gw-label" ).length ) { $( "#place_order" ).after( img ); } } $( document.body ).on( "updated_checkout", placeLabel ); placeLabel(); } ); </script>'; } );The problem seems to be that the scope was limited to the checkout page which didn’t work well with the checkout AJAX:
function is_test_active(): bool { return function_exists( 'is_checkout' ) && is_checkout() && ! is_wc_endpoint_url( 'order-received' ) && ! is_wc_endpoint_url( 'order-pay' ); }Testing the checkout is a pretty common task. Maybe, you could find a better solution for this.
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
You must be logged in to reply to this topic.