In my WooCommerce project, in the functions.php file I have written the following function which runs when the WooCommerce shop page loads all products. I have found the source of the problem but can not figure out why it happens.
Somehow only one can exist between: $prodVars, $prodVar or $prodPrices. If all three are active (uncommented) then the shop page loop breaks and shows the first item only. If I comment two of those variables the loop runs perfectly and displays all information.
Is there something that I misunderstood and used incorrectly?
function get_desc(){
$prodID = get_the_ID();
$product = wc_get_product($prodID);
$product2 = wc_get_product($prodID);
$prodDesc = $product->get_short_description();
echo "<div class='prodDetWrap'>";
echo "<div class='prodVariations'>";
$prodVars = $product->get_attributes();
$prodVar = $product->get_variation_attributes();
$prodPrices = $product2->get_variation_prices();
$prodPrice = $prodPrices['price'];
$prod1Price = current($prodPrice);
$prodCnt = 0;
echo "</div>";
if($prodDesc !== "NULL"){
echo "<p>";
echo $prodDesc;
echo "</p>";
}else{
;
}
echo "<p class='disclaimer'>Er varen ikke på lager, bestiller vi dem hjem til jer.</p>";
echo "</div>";
}
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
add_action( 'woocommerce_after_shop_loop_item_title', 'get_desc', 12);