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

时间:2015-05-08 07:58:34

标签: php wordpress woocommerce

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

我目前正在使用挂钩对下载按钮进行硬编码(连同免责声明文字),以便在我的所有产品之后出现。 meta,这是在我的主题函数中添加的代码.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中提取的链接。

提前致谢!

1 个答案:

答案 0 :(得分:0)

如果您在单个产品页面上,则可以使用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>';
}