Woocommerce:创建产品图片的下载链接

问题描述:

请查看我的示例产品页面:http://snshpl.com.sg/product/swa-8003-t/一个>

Please have a look at my sample product page: http://snshpl.com.sg/product/swa-8003-t/

我目前正在使用钩子对下载按钮(连同免责声明文本)进行硬编码,以便在我所有产品的元数据之后立即显示,这是在我的主题的functions.php 中添加的代码:

I'm currently using hooks to hardcode the download button (together with a disclaimer text) to appear right after all my products' meta, this is the code added in my theme's functions.php:

add_action('woocommerce_product_meta_end','disclaimer');

function disclaimer(){
    echo '<br /><br /><a href="#" class="single_add_to_cart_button button     
    alt">Download</a><p id="disclaimer-text"><br /><br />*Color Disclaimer: 
    Due to the limitations of desktop scanners and the relative 
    inconsistencies of various display monitors, the colors you see on your 
    screen may not be a totally accurate reproduction of the actual product. 
    We strive to make our colors as accurate as possible, but screen images 
    are intended as a guide only and should not be regarded as absolutely 
    correct. If you would like to see a sample of any product shown on our 
    site, please call Customer Service at 6365 3383 or visit our contact 
    page.</p>';
}

我的问题是如何提取显示图像的网址并将其添加到下载按钮的链接中?我尝试了各种方法,但不确定如何访问我知道在文件 product-image.php 中提取的链接.

My question is how do I extract the url of the image shown and add it to the link of the download button? I've tried various methods but not sure how to access the link which I know is extracted in the file product-image.php.

提前致谢!

如果您在单个产品页面上,您可以使用 wp_get_attachment_url( get_post_thumbnail_id() );代码>

If you're on the single product page, you can add the featured image url to your custom button with wp_get_attachment_url( get_post_thumbnail_id() );

在您的示例中:

add_action('woocommerce_product_meta_end','disclaimer');

function disclaimer(){
    echo '<br /><br /><a href="'.wp_get_attachment_url( get_post_thumbnail_id() ).'" class="single_add_to_cart_button button     
    alt">Download</a><p id="disclaimer-text"><br /><br />*Color Disclaimer: 
    Due to the limitations of desktop scanners and the relative 
    inconsistencies of various display monitors, the colors you see on your 
    screen may not be a totally accurate reproduction of the actual product. 
    We strive to make our colors as accurate as possible, but screen images 
    are intended as a guide only and should not be regarded as absolutely 
    correct. If you would like to see a sample of any product shown on our 
    site, please call Customer Service at 6365 3383 or visit our contact 
    page.</p>';
}