I'm trying to set a global variable as a flag. I want to use that in the thankyou.php template to show a custom message when the ordered items are not in stock. It doesn't work.
My code in functions.php:
<?php
global $woocommerce;
global $flag_custom_order;
$flag_custom_order=false;
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values) {
$_product = wc_get_product( $values['data']->get_id());
$stock=$_product->get_stock_quantity();
if ($stock <= '0') :
$flag_custom_order=true;
endif;
}
In thankyou.php template i add this: