skip to Main Content

This or function is not operative as the declaration is showing on all products and not just those listed here. What am I doing incorrectly?

   add_action( 'woocommerce_after_single_product_summary' , 'bbloomer_add_below_prod_gallery', 5 );
function bbloomer_add_below_prod_gallery() {
global $product;
$id = $product->id;
if($id==5735 || 9212 || 5782 || 5781 || 5775 || 5770 || 5764 || 5757 || 5752 || 574 || 5740 || 5725){
   echo '<div class="woocommerce-product-gallery" style="padding: 1em 2em; clear:left;">';
   echo '<center><h2>Conversion Chart</h2></center><img class="conversion" src="https://www.tattiniboots.com/wp-content/uploads/2019/02/conversion-1.png">';
   echo '</div>';
}
}

2

Answers


  1. You have to repeat $id==number each time, but it’s better to put those number in a array and then use in_array function like so:

    $myValues=[5735, 9212, 5782, 5781, 5775, 5770, 5764, 5757, 5752, 574, 5740, 5725];
    if(in_array($id, $myValues)){...}
    
    Login or Signup to reply.
  2. Your If statements are wrong. When using or || you should do them like this

    $id == 123 || $id == 456

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search