Support Forum
Hi guys, how are you?
I need help with a bug I found.
I created some image galleries with advanced image on the woocommerce product pages. However, I found that if I add an image to these galleries, I will no longer be able to change the highlighted image of the product.
I have already rewritten the code, I have redid the advanced images and the bug continues, it is only possible to change the product images if there is no photo in the gallery created with advanced images from the metabox.
I hope you can help me.
Thanks
Hi Felipe,
That was not a bug. The field type image_advanced has the setting 'multiple' => true
which means the value is saved in the database as a serialized array, not only one attachment ID as featured image. You can use the field type single_image instead of and refer to this topic to replace the default featured image box with a custom field.
https://support.metabox.io/topic/single-image-field-with-the-id-_thumbnail_id-is-not-showing-after-latest-updates/
Hi Long Nguyen.
Thanks for your feedback, but I'm not really trying to replace the product's featured image on woocommerce. I added a gallery with multiple images with the metabox, they are complementary images to the product, and when adding an image to this gallery there is an error that I can no longer change the featured image of the product (official of woocommerce). It is only possible to change the product image when I remove 100% of the images from the gallery created with the metabox.
Hi Filipe,
Can you please share the code that creates meta box and custom fields for the post-type Product? I will check it on my end.
Hi, Long Nguyen, of course I can.
It is a long code because we have several fields, from attachments to fields with texts and complementary information.
Thanks,
https://pastebin.com/dcJv5Lny
Hi Filipe,
Use your code to create custom fields on the product editing page, I do not see any issue. Screen record https://share.getcloudapp.com/12uAGeAW.
Please follow the Debugging Information step here https://support.metabox.io/topic/how-to-create-a-new-topic/ to troubleshoot this issue. Let me know how it goes.
Hi Long Nguyen,
After saving or updating the product, did you try to remove or change the featured image of the product?
First test with a product with several images added in the galleries created with metabox:
https://share.getcloudapp.com/nOuoAoG5
Second test removing advanced image images created with metabox:
https://share.getcloudapp.com/xQubG7Yo
The problem occurs after we save the product with the images added to the gallery created by the metabox.
Hi,
Yes, it still works when I remove/change the featured image of the product. Screen record https://share.getcloudapp.com/E0uYDeb6
It is possible that there is a conflict between plugins. You can try to follow the Debugging Information on the reply above to troubleshoot this issue.
Hi,
I discovered the conflict, I was using ACF to create personalized fields for users, photographers and products in the attachments and that was what was causing conflict.
Thanks for your help was lost before, for anyone who has the same problem follows solution used with metabox to replace the ACF plugins.
<?php
add_filter( 'rwmb_meta_boxes', 'metabox_attachment_photographer_register_meta_boxes' );
function metabox_attachment_photographer_register_meta_boxes( $meta_boxes ) {
$meta_boxes[] = [
'title' => esc_html__( 'Fotográfo', 'decostore' ),
'id' => 'attachment_photographer',
'context' => 'normal',
'post_types' => 'attachment',
'media_modal' => true,
'fields' => [
[
'type' => 'user',
'name' => esc_html__( 'Fotográfo', 'decostore' ),
'id' => 'attachment_photographer',
'field_type' => 'select',
'query_args' => [
'role' => 'photographer',
'order' => 'ASC',
'orderby' => 'title',
],
],
],
];
return $meta_boxes;
}
Let me know if you have any questions 🙂