Skip to content
Advertisement

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

Advertisement

Answer

One easy way to hide this would be to just use CSS.

if the theme is using the body_class() function then the page will have its own body class. Something like .postid-1514 and you can hide it using .postid-1514 .download { display: none; } this will completely hide it.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement