我正在尝试在我的下载标签中显示pdf,以便当有人查看我的产品时,他们可以在新窗口中打开pdf。我通过媒体按钮将pdf上传到产品。我的回调看起来像这样,$附件似乎空洞的想法?:
function woo_new_product_tab_content_downloads() {
global $woocommerce, $product, $post;
$product_id = $post->ID;
echo $product_id;
$product = new WC_Product( $product_id );
print_r($product);
// The new tab content
$args = array(
'post_type' => 'attachment',
'orderby' => 'menu_order',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $product_id,
'post_mime_type' => array( 'application/pdf')
);
$attachments = get_posts( $args );
//print_r($attachments);
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<p><a href="';
echo wp_get_attachment_url( $attachment->ID );
echo '">';
echo wp_get_attachment_image( $attachment->ID, '', true );
echo ' ';
echo apply_filters( 'the_title', $attachment->post_title );
echo '</a>';
echo '</p>';
}
}
}
答案 0 :(得分:0)
作为对自己的回答,请务必附上正确的文件类型