Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • raphaello77

    (@raphaello77)

    Hmm I did try that filter but something didnt want to work cant remember exactly what at the moment.. Ill try it again ??

    What i am trying to do is to add your great image upload feature (that i really like!!) and combine it with a woocommerce product listing widget and a custom taxonomy selector..

    Here it is:
    https://github.com/raphaello77/woocommerce-image-upload-and-product-listing-widget/blob/master/image_product_listing_widget.php

    I added a whole lot of file extra fields there..

    PS: Thanks for a really great plugin Brady!

    raphaello77

    (@raphaello77)

    I did it like this:

    first overloaded this class function and added my field extra_field

    public function form_fields() {
    		return array(
    			'image_size',
    			'link',
    			'link_text',
    			'link_classes',
    			'text',
    			'extra_field',
    		);
    	}

    then used this filter

    add_filter( 'simple_image_widget_instance', function( $instance, $new_instance, $old_instance, $id_base ) {
    
    		$instance['show'] = absint( $new_instance['extra_field'] );
    
    		return $instance;
    }, 10, 4 );

    then added the input field with this action

    add_action( 'simple_image_widget_field-extra_field', function( $instance, $that ) {
    	?>
    	<p>
    		<label for="<?php echo esc_attr( $that->get_field_id( 'extra_field' ) ); ?>">Extra field</label>
    		<input class="widefat" id="<?php echo esc_attr( $that->get_field_id( 'extra_field' ) ); ?>" name="<?php echo esc_attr( $that->get_field_name( 'extra_field' ) ); ?>" type="number" step="1" min="1" max="" value="<?php echo $instance['extra_field'] ?>">
    	</p>
    	<?php
    }, 10, 2);

    Workes good and seemed correct atleast..

Viewing 2 replies - 1 through 2 (of 2 total)