Custom Fields
Re-Envisioned
Support General Bug image advanced with woocommerce featured image

  • Creator
    Topic
  • #27903
    Resolved Felipe Pereira
    Participant

    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

Viewing 9 replies - 1 through 9 (of 9 total)
  • Author
    Replies
  • #27905
    Long Nguyen
    Moderator

    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://metabox.io/support/topic/single-image-field-with-the-id-_thumbnail_id-is-not-showing-after-latest-updates/

    #28282
    Felipe Pereira
    Participant

    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.

    #28286
    Long Nguyen
    Moderator

    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.

    #28309
    Felipe Pereira
    Participant

    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

    #28322
    Long Nguyen
    Moderator

    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://metabox.io/support/topic/how-to-create-a-new-topic/ to troubleshoot this issue. Let me know how it goes.

    #28333
    Felipe Pereira
    Participant

    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.

    #28348
    Long Nguyen
    Moderator

    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.

    #28436
    Felipe Pereira
    Participant

    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;
    }
    
    #28440
    Long Nguyen
    Moderator

    Let me know if you have any questions 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.