Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to add a button to my product pages which allows the user to request a sample, however I only need this to be seen on products within certain catagories. I've managed to get the button working by adding this code into the meta.php file:

<div id="requestsample">
<a class="fancybox button" href="#contact_form_pop">Request a Sample</a>
<div class="fancybox-hidden" style="display: none;">
<div class="hentry" id="contact_form_pop" style="width: 500px; height: auto;"><?php echo do_shortcode( '[contact-form-7 id="269" title="Request Sample"]' ); ?></div>
</div>

But I'm not sure how to get it to only show on products within these categories. I tried wrapping my code in:

<?php if (in_category('11,12,13')) { } ?>

But this didn't work. I'm thinking maybe it's because my categories were created in woocommerce.

Any help will be greatly appreciated!

Thanks in advance!

EDIT

I've just tried this but still nothing...

<?php if ( is_product_category() ) {
if ( is_product_category( 'coving' ) ) {
echo '<div id="requestsample"><a class="fancybox button" href="#contact_form_pop">Request a Sample</a><div class="fancybox-hidden" style="display: none;"><div class="hentry" id="contact_form_pop" style="width: 600px; height: 500px; overflow-x: hidden"><?php echo do_shortcode( '[contact-form-7 id="269" title="Request Sample"]' ); ?></div></div></div>';
} elseif ( is_product_category( 'skirting-boards' ) ) {
echo '<div id="requestsample"><a class="fancybox button" href="#contact_form_pop">Request a Sample</a><div class="fancybox-hidden" style="display: none;"><div class="hentry" id="contact_form_pop" style="width: 600px; height: 500px; overflow-x: hidden"><?php echo do_shortcode( '[contact-form-7 id="269" title="Request Sample"]' ); ?></div></div></div>';
} elseif ( is_product_category( 'dado-rails' ) ) {
echo '<div id="requestsample"><a class="fancybox button" href="#contact_form_pop">Request a Sample</a><div class="fancybox-hidden" style="display: none;"><div class="hentry" id="contact_form_pop" style="width: 600px; height: 500px; overflow-x: hidden"><?php echo do_shortcode( '[contact-form-7 id="269" title="Request Sample"]' ); ?></div></div></div>';
} elseif ( is_product_category( 'indirect-lighting-by-orac' ) ) {
echo '<div id="requestsample"><a class="fancybox button" href="#contact_form_pop">Request a Sample</a><div class="fancybox-hidden" style="display: none;"><div class="hentry" id="contact_form_pop" style="width: 600px; height: 500px; overflow-x: hidden"><?php echo do_shortcode( '[contact-form-7 id="269" title="Request Sample"]' ); ?></div></div></div>';
} else {
echo ' ';
}

}?>

Anyone have any other ideas? Thanks

share|improve this question
add comment

1 Answer

You are trying to echo PHP code. Additionally you are using single and double quotes wrong.

You should just fix the formatting of your echo() functions. Something like this:

echo '<div id="requestsample"><a class="fancybox button" href="#contact_form_pop">Request a Sample</a><div class="fancybox-hidden" style="display: none;"><div class="hentry" id="contact_form_pop" style="width: 600px; height: 500px; overflow-x: hidden">';
echo do_shortcode( '[contact-form-7 id="269" title="Request Sample"]' );
echo'</div></div></div>';
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.