• Hi there,

    I’m using GF to create a custom product submission form for our (dokan) vendors and while the submission form is working like a charm, I’m struggling to get the featured image and product gallery to update.

    The edit form pulls in a url param, then sets all the various fields, which is all working. I then created a preview panel to show the existing attached images, which is also working, including the ability to remove images from the product.

    I’ve set the image field in the update feed and set a meta value for the _product_image_gallery, then showing the submitted image in the confirmation, which is getting picked up, but the images are not being saved to the product.

    I recorded a quick video showing the add/update workflow:
    https://www.loom.com/share/e2df273c033a4061ac9d77cc50b40bce

    I had a suspicion that it might have something to do with the media library plugin, so i dug through the plugin code and see it integrates with APC plugin.

    Any ideas what I’m doing wrong?

    We’re meant to be launching the marketplace tomorrow and this is the last thing I’m stuck on. Any ideas / suggestions would be very much appreciated ??

    TIA,
    Chris

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Alex Chernov

    (@alexusblack)

    Hi Chris,

    does the featured image update works for you? I tested it with WooCommerce products (not dokan) and it was working. The plugin simply uploads image to media library and then tries to set it as featured via WP function. If not, there is a possibility that dokan stores the featured image in different format.

    For the media library if you are using a meta field there is currently no image upload processing there, so unless you have some 3rd party plugin that uploads images and stores them in the field as simple list of IDs it wouldn’t work.

    Sorry, but I won’t be able to investigate in detail and release an update for you before your launch, but feel free to modify the plugin code based on suggestions above if you can.

    Thread Starter Chris Rault

    (@connectr)

    Hi Alex,

    Thanks for taking the time to reply, I really appreciate it.

    I’m actually bypassing Dokan for the product forms, so my GF form is saving directly to the WC products.

    I remembered it working before on my old dev site, so fired it up, tested the form and it updated the fields, but as a new product. I then realized I still had the APC feed enabled, which has the additional setting to select which fields should upload to the media library. Once I removed the APC feed, the updating stops working all together.

    Being that it’s working in the APC plugin, I decided to check the media library plugin and noticed it’s using APC’s gform_advancedpostcreation_post_after_creation action hook:

    add_action( 'gform_advancedpostcreation_post_after_creation', array( $this, 'apc_custom_field_integration' ), 10, 4 )

    and further down:

    ## ADVANCED POST CREATION
    
    public function apc_custom_field_integration( $post_id, $feed, $entry, $form ) {
    
        $auto_custom_fields = array(
            '_product_image_gallery' /* WooCommerce product gallery */
        );
    
        /**
            * Filter which custom fields GP Media Library will attempt to convert to use image IDs.
            *
            * @param array $auto_custom_fields A list of custom field keys that should use image IDs.
            * @param int $post_id ID of the post for which custom fields are being processed.
            * @param array $entry The current entry ID.
            * @param array $form The current form.
            * @param array $feed The current APC feed.
            *
            * @since 1.2.8
            *
            */
        $auto_custom_fields = gf_apply_filters( array(
            'gpml_auto_convert_custom_fields',
            $form['id']
        ), $auto_custom_fields, $post_id, $entry, $form, $feed );
    
        $mappings = rgars( $feed, 'meta/postMetaFields', array() );
    
        foreach ( $mappings as $mapping ) {
    
            $key = $mapping['key'] == 'gf_custom' ? $mapping['custom_key'] : $mapping['key'];
            if ( ! in_array( $key, $auto_custom_fields ) ) {
                continue;
            }
    
            $field = GFAPI::get_field( $form, $mapping['value'] );
            if ( ! $field || ! $this->is_applicable_field( $field ) ) {
                continue;
            }
    
            $value = $this->acf_get_field_value( 'id', $entry, $field, true );
            if ( ! $value ) {
                continue;
            }
    
            if ( is_array( $value ) ) {
                $value = implode( ',', $value );
            }
    
            update_post_meta( $post_id, $key, $value );
    
        }
    
    }

    Do you think adding an action hook to the update post plugin, combined with duplicating the function call would work?

    Something along the lines of:

    ‘add_action( ‘gform_postupdate_post_after_creation’, array( $this, ‘apc_custom_field_integration’ ), 10, 4 );’

    https://www.loom.com/share/ba7f6b71b2a549b39d6e66dbc5f183d1

    Thanks again ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Updating a products featured image and gallery’ is closed to new replies.