Reputation: 21
I am using Woocommerce 2.4.4 and Wordpress 4,3, I have read many suggestions for making changes to woocommerce shop page; however I cannot find anyone who addresses my specific request. I have limited understanding of Woocommerce; however I have been trying to solve my request, but to no avail.
I want to display the wordpress caption field for each image in the wordpress media library in my woocommerce shop page but not on the individual products.
I have made changes to my child theme, Deli (A woocommerce theme) functions.php . I added the following to the child functions.php.
function wp_get_attachment( $attachment_id ) {
$attachment = get_post( $attachment_id );
return array(
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt',
true ),
**'caption' => $attachment->post_excerpt,**
'description' => $attachment->post_content,
'href' => get_permalink( $attachment->ID ),
'src' => $attachment->guid,
'title' => $attachment->post_title
);
}
I believe the field that has the image caption is 'caption' => $attachment->post_excerpt, as defined above.
I am trying to edit the Woocommerce Archive-product.php but do not know what to add or where to add it in the archive-product.php.
Upvotes: 1
Views: 2682
Reputation: 11808
Hey as per your requirement have tried a code which might help you in your case or you can customize it further as per your request.
Add the following code to your Theme's functions.php.
Note: Its better to create a child theme first and do your customization in it so that the customization won't get overwritten when the theme updates.
add_filter( 'wp_get_attachment_image_attributes','wdm_shop_image_caption_func', 10,3 );
function wdm_shop_image_caption_func($attr, $attachment, $size){
if($size=='shop_single'){
unset($attr['title']);
}
elseif($size=='shop_catalog'){
$attr['title']=$attr['alt'];
}
return $attr;
}
Make sure that you set Caption for every Product's Images.
Upvotes: 1