Support » Plugin: WooCommerce » Used for variants set to default (admin)

  • Resolved flexidesign

    (@flexidesign)


    Hi,
    I was made research by Google from this year to past 5 years. (also this forum)
    I was found only one solution – which now isn’t working after WooCommerce is in newer version.

    What i would like to?
    Simply i would like to have Default Ticked checkbox:”used for variants” after creating Attributes.

    Who can help me with this problem?
    I was saw that many people asked about this feature – but nobody knows how to fix this?

    Best Regards
    Jarek

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support wbrubaker

    (@wbrubaker)

    Howdy 🙂

    Was this the solution that you were using: https://stackoverflow.com/questions/42282854/woocommerce-show-used-for-variations-tickbox-custom-product-type

    If not, you might want to give that a try.

    Hi,
    Thank you for this – i was try to use this before i was make this ticket.
    So – im not a programmer – and when i simpy copy this code:

    $( 'body' ).on( 'woocommerce_added_attribute', function( event ){
        $('.woocommerce_attribute_data .enable_variation').addClass('show_if_vp_extended').show();
    });

    It isn’t work. I was read on begining that this guy was created custom variable: vp_extended .. i havent this.

    So could you tell me how i must modify this code to run it correctly in normal product mode? (i use: simply Prdocut with variations, choose earlier created attributes).

    Plugin Support wbrubaker

    (@wbrubaker)

    That code is JavaScript and would somehow need to be included when viewing a product edit screen. The approach that I would recommend would be to create a plugin for this purpose. If you’re unfamiliar with how that is done, here is a good starting point: https://developer.wordpress.org/plugins/

    And a useful function for enqueueing JavaScript in WordPress: https://developer.wordpress.org/reference/functions/wp_enqueue_script/

    Plugin Support Jesse Pearson

    (@jessepearson)

    Automattic Happiness Engineer

    @flexidesign I went off of the previously mentioned Stack Overflow link and modified it to make sure it will check that box. This worked for me:

    
    function producttype_custom_js() {
    
    	if ( 'product' !== get_post_type() ) {
    		return;
    	}
    	?>
    	<script type='text/javascript'>
    
    		$( 'body' ).on( 'woocommerce_added_attribute', function( event ){
    			$( '.woocommerce_attribute_data .enable_variation .checkbox' ).prop( 'checked', true );
    		});
    	</script>
    <?php 
    } 
    add_action( 'admin_footer', 'producttype_custom_js' );  
    

    Here is an example of it working.


    Link to image: http://cld.wthms.co/ZKhJ69

    I am marking this thread as resolved, as this solution is working.

    Hi,
    Thank you for replay! 😀
    My programmer friend was made this easier 😀

    Simply add Custom Snippets plugin, and activate this code in backend:

    function always_true( $value ) {
        return 1;
    }
    
    add_filter( 'woocommerce_attribute_default_is_variation', 'always_true' );

    Thanks anyway for script. I was forgot that i was create this ticket.
    Best of all

    Plugin Support Jesse Pearson

    (@jessepearson)

    Automattic Happiness Engineer

    @flexidesign Yes, I did not know about that filter. That would do it, as well. You can reduce the code to a single line:

    
    add_filter( 'woocommerce_attribute_default_is_variation', '__return_true' );
    
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Used for variants set to default (admin)’ is closed to new replies.