Try something like this:
<?php
$order_id = $order->get_id();
$order = wc_get_order( $order_id );
$items = $order->get_items();
$is_valid = null;
foreach ( $items as $item_id => $item_data ) {
$product = $item_data->get_product();
$categories = array();
$terms = get_the_terms( $product->get_id(), 'product_cat' );
if ( is_wp_error( $terms ) || empty( $terms ) ) {
continue;
}
foreach ( $terms as $term ) {
if( false !== $is_valid && strtolower($term->name) === 'registration'){
$is_valid = true;
continue;
}
$is_valid = false;
}
}
if ( $is_valid ) {
// Run any html code after this closing php tag -> ?>
<p>
Didn't get your gear yet? Click <a href="https://flexfootball.com/shop/">HERE</a> to order yours!
</p>
<?php // Close "product is a registration form" condition
}
The basic gist is that you are setting up $is_valid
as a NULL
value. If any category is not registration
, then $is_valid
becomes boolean false
. If the category is registration
AND $is_valid
is not strictly (!==
) false
, set $is_valid
to boolean true
.
Finally, after the loops are done, if $is_valid
is true
, add the message.