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

时间:2022-10-25 10:10:51

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

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

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:

我目前正在使用钩子来硬编码下载按钮(连同免责声明文本),以便在我的所有产品元素之后出现,这是我主题的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>';
}

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.

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

Thanks in advance!

提前致谢!

1 个解决方案

#1


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() );

如果您在单个产品页面上,则可以使用wp_get_attachment_url(get_post_thumbnail_id())将特色图像URL添加到自定义按钮;

In your example:

在你的例子中:

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>';
}

#1


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() );

如果您在单个产品页面上,则可以使用wp_get_attachment_url(get_post_thumbnail_id())将特色图像URL添加到自定义按钮;

In your example:

在你的例子中:

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>';
}