'Refer to specific product ID in WordPress / WooCommerce in PHP

I have this script that adds a download button to every product page in WooCommerce but I need to exclude a product page from having the download button.

I tried changing the first line to

if ( is_product() || $id() != "1514" ){  

but it is failing, I think I am on the right track but need to reference it correctly (It should only enter the if function if is a product AND its not product ID 1514)

if ( is_product()){ 
$link = get_the_title();
$link =  str_replace(' ', '-', $link);
echo '<div class="download">';
echo '<a href="';
echo bloginfo('url');
echo '/pdf/Spec-Sheet-';
echo $link . '.pdf';
echo ' " title="Download Spec Sheet" target="_blank">';
echo 'DOWNLOAD SPEC SHEET';
echo '</a>'; 
echo '</div>'; }

Thanks



Solution 1:[1]

the answer is

if(is_product() && get_the_id() == 1253) {
    //do stuff
}

works in pre_get_posts - didn't test in the product template, but if it doesn't, make sure you are in the loop and it'll work for sure.

Solution 2:[2]

You can try this!

global $product;
if ( $product->get_id() != 1514 ) {
  
// your logic here 
  
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Flo
Solution 2 stiviniii