WordPress.org

Ready to get started?Download WordPress

Forums

Enhanced Media Library
[resolved] WooCommerce integration (8 posts)

  1. cvokk
    Member
    Posted 3 months ago #

    Hello,
    for a couple of hours now I am trying to integrate EML with WooCommerce.
    I am using variable product and there is a selector for variation image.

    From their code, the frame to select the image is opened like so:

    // If the media frame already exists, reopen it.
    if ( variable_image_frame ) {
    	variable_image_frame.uploader.uploader.param( 'post_id', setting_variation_image_id );
    	variable_image_frame.open();
    	return;
    } else {
    	wp.media.model.settings.post.id = setting_variation_image_id;
    }
    
    // Create the media frame.
    variable_image_frame = wp.media.frames.variable_image = wp.media({
    	// Set the title of the modal.
    	title: '<?php echo esc_js( __( 'Choose an image', 'woocommerce' ) ); ?>',
    	button: {
    		text: '<?php echo esc_js( __( 'Set variation image', 'woocommerce' ) ); ?>'
    	}
    });
    
    // When an image is selected, run a callback.
    variable_image_frame.on( 'select', function() {
    
    	attachment = variable_image_frame.state().get('selection').first().toJSON();
    
    	setting_variation_image.find( '.upload_image_id' ).val( attachment.id );
    	setting_variation_image.find( '.upload_image_button' ).addClass( 'remove' );
    	setting_variation_image.find( 'img' ).attr( 'src', attachment.url );
    
    	wp.media.model.settings.post.id = wp_media_post_id;
    });
    
    // Finally, open the modal.
    variable_image_frame.open();

    Similar code opens the media frame to select multiple images for the product, this frame is also without EML filters.
    As there may be hundreds of products and variations, the filters are necessary.

    Do you know how to alter the code to open the frame along with the EML filters? I see that in eml-media-uploader.js you extend AttachmentsBrowser but I guess the default media frame invoked by the wp.media() is using some other defaults and so far I wasn't able to find out how to hook EML filters there.

    Please let me know if you have any advice on this.

    Thank you very much!

    Best regards
    Vit

    http://wordpress.org/plugins/enhanced-media-library/

  2. webbistro
    Member
    Plugin Author

    Posted 3 months ago #

    Hello,

    Thank you for your question and information. I will definitely make EML compatible with WooCommerce, but I need a few days to check this and some other bugs (found by my clients and myself) for the new upgrade... I will let you know as soon as it works.

    Happy New Year!

    Nadia

  3. cvokk
    Member
    Posted 3 months ago #

    Thanks!

    Happy New Year!

    Vit

  4. cvokk
    Member
    Posted 3 months ago #

    Hi, is there any progress regarding this issue?
    How can I help?

    Regards
    Vit

  5. webbistro
    Member
    Plugin Author

    Posted 3 months ago #

    Hello Vit,

    Sorry for delay.

    You have to change WooCommerce code somehow like this:

    // Create the media frame.
    variable_image_frame = wp.media.frames.variable_image = wp.media({
    	// Set the title of the modal.
    	title: '<?php echo esc_js( __( 'Choose an image', 'woocommerce' ) ); ?>',
    	button: {
    		text: '<?php echo esc_js( __( 'Set variation image', 'woocommerce' ) ); ?>'
    	},
    	states : [
    		new wp.media.controller.Library({
    			title: '<?php echo esc_js( __( 'Choose an image', 'woocommerce' ) ); ?>',
    			filterable :	'all'
    		})
    	]
    });

    Source: /wp-includes/js/media-views.js (for example line 1249, 1267).

    It would be nice also if you contacted WooCommerce developers. I can't add this functionality via EML because I don't want to change media popup settings of other plugins. Their developers may have reasons to not use filters. EML, by default, extends attachment filters if they are present in fact.

    Nadia

  6. cvokk
    Member
    Posted 3 months ago #

    Perfect, it works now.
    Thank you!

    Vit

  7. cvokk
    Member
    Posted 3 months ago #

    Also sent pull request with those changes on GitHub.

    Regards
    Vit

  8. webbistro
    Member
    Plugin Author

    Posted 3 months ago #

    Thank you very much, Vit!

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.