I made this:
global $product;
$koostis = $product->get_attribute( 'color' );
echo "<h2>Color: ".$koostis."</h2>";
This show a color attribute on my product.
But if a product don't have a color attribute this script show only: "Color:" of course.
I try to use:
if (isset($koostis)) {
echo "<h2>Color: ".$koostis."</h2>";
}
But don't work because the variable is not exactly empty, i need a method to hide echo "<h2>Color: ".$koostis."</h2>"; if the variable not contain data.
Exist?
If the variable is blank, you can check for that with empty:
if (!empty($koostis)) {
echo "<h2>Color: ".$koostis."</h2>";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With