正确的方法似乎是使用挂接的自定义函数
woocommerce_before_add_to_cart_form
动作挂钩,将代码嵌入其中并在产品页面中显示。
511
是一个
产品类别
(并且不是普通WP类别。如果不是,您将不得不创建它,并用您的新产品类别的名称、slug或ID替换此ID。
这应该是您的代码:
add_action('woocommerce_before_add_to_cart_form','my_custom_product_content', 1, 0 );
function my_custom_product_content(){
global $post, $product;
if(has_term( array(531), 'product_cat', $post->ID )) {
if ( current_user_can('manage_options') ) {
?>
<p>
↓ Download Image<br />
<a href="<?php $image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'web', true);
echo $image_url[0]; ?>" ><img src="<?php bloginfo ('template_url' )?>/img/downloadForWeb.png" alt="download for web" /></a><br />
<a href="<?php $image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'print', true);
echo $image_url[0]; ?>" class="download"><img src="<?php bloginfo ('template_url' )?>/img/downloadForPrint.png" alt="download for print" /></a><br />
<a href="<?php $image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'', true);
echo $image_url[0]; ?>" class="download"><img src="<?php bloginfo ('template_url' )?>/img/downloadForProPrint.png" alt="download for pro print" /></a><br />
</p>
<?php
} else {
?>
<h2>Special permission required</h2>
<p>In order to use this image you need special permission from the admin, please fill in the form below and we'll get back to
you as soon as possible...</p>
<?php echo do_shortcode( '[contact-form 11 "special permission"]' ) ?>
<?php
}
} else {
?>
<p>
↓ Download Image<br />
<a href="<?php $image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'web', true);
echo $image_url[0]; ?>" ><img src="<?php bloginfo ('template_url' )?>/img/downloadForWeb.png" alt="download for web" /></a><br />
<a href="<?php $image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'print', true);
echo $image_url[0]; ?>" class="download"><img src="<?php bloginfo ('template_url' )?>/img/downloadForPrint.png" alt="download for print" /></a><br />
<a href="<?php $image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'', true);
echo $image_url[0]; ?>" class="download"><img src="<?php bloginfo ('template_url' )?>/img/downloadForProPrint.png" alt="download for pro print" /></a><br />
</p>
<?php
}
}
测试和工作