Display additional product information (e.g. image caption) when hovering product image

↘锁芯ラ 提交于 2020-01-07 01:56:11

问题


I'm using using the WooCommerce plugin for WordPress to display my products. The thing is, when you are viewing the product category (archive), you can see the product name, image and price, but that doesn't really say all that much about exactly what the product is.

What I would like is for some more information to become available when you hover the product images. Something a bit like this. Would it be possible to retrieve some of the information about the image, that I can enter in the WordPress media libray: title, caption alt text or description?

You can check the webshop here.

EDIT:

I found that editing the content-product.php file in the WooCommerce plugin folder, if I put this:

?>
random text
<?php

somewhere inside the php tags in the <li> section of that file, I could get 'random text' to show either above or below the product image on the product archive page. So, if I could replace that with a function that would retreive for instance the product image caption or some custom field that I can fill out for each product, that would go a long way towards solving the issue. So, if anyone knows of a function that does this, please share it here.


回答1:


hello sir just use this plugin
 https://wordpress.org/plugins/woocommerce-custom-product-data-fields/

for retrieving any costume fields do like this
Retrieving multiselect value



global $wc_cpdf;
$multiselect = $wc_cpdf->get_value($post->ID, '_mymultiselect');

foreach ($multiselect as $value) {

  echo $value;

}


Retrieving image value



global $wc_cpdf;

$image_id = $wc_cpdf->get_value($post->ID, '_myimage');

$size = 'thumbnail';

$image_attachment = wp_get_attachment_image($image_id, $size);

echo $image_attachment;

}


来源:https://stackoverflow.com/questions/35985494/display-additional-product-information-e-g-image-caption-when-hovering-produc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!