-
AuthorPosts
-
August 2, 2024 at 12:52 pm #209230
Matthew SemrauParticipantIssue Description
We purchased the Bulky WooCommerce Bulk Edit Products plugin with the intention of bulk editing variation galleries for variation products, which are managed by the Product Gallery Slider for WooCommerce plugin by Codeixer. However, Bulky does not currently support bulk editing of custom gallery fields. We are trying to extend Bulky to add a custom gallery column type so we can edit the custom gallery meta field (
wavi_value
), but our attempts have not been successful.Desired Functionality
We want to be able to:
1. **Bulk Edit Variation Galleries**: Specifically, we need to bulk edit the variation galleries managed by thewavi_value
meta field.
2. **Add a Custom Gallery Column Type**: Extend Bulky to support a new column type for galleries, enabling us to bulk edit thewavi_value
meta field.Steps Taken and Code Implemented
We have tried to implement the following steps:
1. Extend Meta Field Types
We added a custom gallery field type by hooking into the
bulky_field_types
filter:php add_filter('bulky_field_types', 'add_custom_gallery_field_type'); function add_custom_gallery_field_type($field_types) { $field_types['gallery'] = __('Gallery', 'textdomain'); return $field_types; }
2. Render the Custom Gallery Field
We implemented the rendering logic for the custom gallery field:
php add_action('bulky_render_field_gallery', 'render_custom_gallery_field', 10, 2); function render_custom_gallery_field($field, $value) { ?> <div class="bulky-gallery-field"> <input type="hidden" name="<?php echo esc_attr($field['id']); ?>" value="<?php echo esc_attr($value); ?>" /> <button type="button" class="button bulky-add-gallery"><?php _e('Add Images', 'textdomain'); ?></button> <div class="bulky-gallery-preview"> <?php if ($value) { $image_ids = explode(',', $value); foreach ($image_ids as $image_id) { $image_url = wp_get_attachment_url($image_id); echo '<img src="' . esc_url($image_url) . '" style="max-width: 100px; margin: 5px;">'; } } ?> </div> </div> <?php }
3. Enqueue Necessary Scripts
We ensured the script for the media uploader is enqueued correctly:
php add_action('admin_enqueue_scripts', 'enqueue_bulky_gallery_scripts'); function enqueue_bulky_gallery_scripts() { wp_enqueue_media(); }
4. JavaScript for Handling the Media Uploader
We added the JavaScript directly to the admin footer for easier debugging:
php add_action('admin_footer', 'add_bulky_gallery_script'); function add_bulky_gallery_script() { ?> <script type="text/javascript"> jQuery(document).ready(function($) { var frame; $(document).on('click', '.bulky-add-gallery', function(e) { e.preventDefault(); if (frame) { frame.open(); return; } frame = wp.media({ title: 'Select or Upload Images', button: { text: 'Use these images' }, multiple: true }); frame.on('select', function() { var attachments = frame.state().get('selection').toJSON(); var ids = attachments.map(function(attachment) { return attachment.id; }).join(','); $('input[name="wavi_value"]').val(ids); // Update the preview var preview = $('.bulky-gallery-preview'); preview.empty(); attachments.forEach(function(attachment) { preview.append('<img src="' + attachment.url + '" style="max-width: 100px; margin: 5px;">'); }); }); frame.open(); }); }); </script> <?php }
5. Handle Saving the Gallery Meta Field
We ensured the data is saved correctly when the product is updated:
php add_action('save_post_product', 'save_woo_gallery_slider_meta', 10, 2); function save_woo_gallery_slider_meta($post_id, $post) { if (isset($_POST['wavi_value'])) { $gallery_ids = sanitize_text_field($_POST['wavi_value']); update_post_meta($post_id, 'wavi_value', $gallery_ids); } } <code></code>
6. Add the Gallery Field to Meta Fields List
We attempted to add the gallery field to the meta fields list:
php add_action('bulky_product_edit_fields', 'add_woo_gallery_slider_field_to_bulky'); function add_woo_gallery_slider_field_to_bulky($fields) { $fields[] = [ 'id' => 'wavi_value', 'label' => __('Woo Gallery Slider', 'textdomain'), 'type' => 'gallery', // Custom gallery type we added 'desc' => __('Add images for the Woo Gallery Slider.', 'textdomain') ]; return $fields; }
Current Issue
Despite implementing the above steps, the custom gallery field is not appearing in the Bulky interface as expected. We have added debug statements, but they are not being logged, indicating that the functions might not be executed.
Request for Assistance
We’d like to be able to bulk edit gallery fields other than the primary product gallery field. That’s the only reason we went with the pro plugin. If we can’t get it to do that we’d like to opt for a refund as we don’t currently have a use for the other features.
-
AuthorPosts
You must be logged in to see replies to this topic. Click here to login or register