I would like to find the lowest regular price of all variations. For this I have written the following code:
add_action( 'woocommerce_before_add_to_cart_form', 'preis_von' );
function preis_von() {
global $product;
global $post;
$theproductid = array(15174, 15175);
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
if(in_array($product_id, $theproductid)) {
$prices = min(get_post_meta( $post->ID, '_regular_price', true ));
//rsort($prices); // sort in descending order
//$minPrice=min($prices);
echo '<div id="preisab" class="abpreis">Preis ab '.$prices.'€ pro Won</div>';
?>
<script>
jQuery(document).ready(function($) {
$( ".variations_form" ).on( "woocommerce_variation_select_change", function () {
document.getElementById("preisab").innerHTML= " ";
});
});
</script>
<?php
}
}
But there is no output. If I use the variation ID instead of $post->ID, I get the output of the regular price for the variation. What did I do wrong?