Reputation: 57
I'm using the following code on my woocommerce shop page.
function uit_productie_badge() {
global $product;
$beschikbaarheid = $product->get_attribute('pa_beschikbaarheid');
echo '<span class="sold-out">' . $beschikbaarheid . '</span>';
if ($beschikbaarheid = "dsgdfsg"){
echo "Hello World!";
}
}
add_action( 'woocommerce_before_shop_loop_item_title', 'uit_productie_badge');
The span
with the badge is showing with the attribute value, however, the if statement is not working.
dsgdfsg
is just random text and should not be in there, however, each product shows the Hello World!
. How can I solve this?
Upvotes: 0
Views: 167
Reputation:
The issue you have is this line;
if ($beschikbaarheid = "dsgdfsg"){
Using a single equals is variable assignment as apposed to checking if it matches, if you use 2 it will work, so this will fix;
if ($beschikbaarheid == "dsgdfsg"){
For example, if you have the following function;
function AssignTo()
{
if (isset($_SESSION['variable']) && $_SESSION['variable'] == true)
{
return true;
}
else
{
return false;
}
}
You could do the following;
if ($a = AssignTo())
{
// The function returned true, so the check is true and $a is set to true
}
else
{
// The function returned false, so the check fails and $a is set to false
}
Upvotes: 2