Woocommerce:创建产品图片的下载链接 [英] Woocommerce: Creating a download link to product image

查看:37
本文介绍了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>';
}

这篇关于Woocommerce:创建产品图片的下载链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆