Single select

This topic contains 5 replies, has 4 voices, and was last updated by Avatar Sushobhan 1 week ago.

  • Author
    Posts
  • #103223
    Avatar
    GutM
    Participant

    How can I make when vendors adding products can only select single attribute option from desplegable?

  • #104575
    Avatar
    Sushobhan
    Keymaster

    Hi,
    Your query isn’t clear. Can you please explain what you want to achieve? If possible a snapshot of the section would be great.
    Thanks

  • #105764
    WCFM Forum
    WCFM Forum
    Keymaster

    Hi,

    Please add this code to your site –

    add_filter( 'wcfm_attribute_limit', function( $limit ) {
    	return 1;
    });

    Add this code to your child theme’s functions.php
    In case you do not have child theme then add code using this plugin –¬†https://wordpress.org/plugins/code-snippets/

    Thank You

  • #106245
    Avatar
    badianafaa
    Participant

    Hello, this snippet work but only alone, beacause when i want to make all attributes required with this snippet :

    add_filter( 'wcfm_product_custom_attributes', function( $taxonomy_fields, $att_taxonomy )
    		{
    			if( isset( $taxonomy_fields[$att_taxonomy] ) && isset( $taxonomy_fields[$att_taxonomy]['options'] ) )
    			{
    				if( isset( $taxonomy_fields[$att_taxonomy]['options']['is_active'] ) )
    				{
    					$taxonomy_fields[$att_taxonomy]['options']['is_active']['custom_attributes'] = array( 'required' => 1, 'required_message' => 'Attributes are required' );
    				}
    				if( isset( $taxonomy_fields[$att_taxonomy]['options']['value'] ) )
    				{
    					$taxonomy_fields[$att_taxonomy]['options']['value']['custom_attributes'] = array( 'required' => 1, 'required_message' => 'Attributes are required' );
    				}
    			}
    			return $taxonomy_fields;
    		}, 50, 2);

    , the limit 1 snippet doesn’t work anymore. Is it possible to make the 2 snippets work correctly together ?

  • #106246
    Avatar
    badianafaa
    Participant

    Idem with this snippet :

    add_filter( 'wcfm_product_custom_attributes', function( $taxonomy_fields, $att_taxonomy )
    		{
    			if( isset( $taxonomy_fields[$att_taxonomy] ) && isset( $taxonomy_fields[$att_taxonomy]['value'] ) )
    			{
    				$attributes = $taxonomy_fields[$att_taxonomy]['value'];
    				$wcfm_attributes = array();
    				if( !empty( $attributes ) )
    				{
    					foreach( $attributes as $acnt => $wcfm_attribute )
    					{
    						$wcfm_attributes[$acnt] = $wcfm_attribute;
    						$wcfm_attributes[$acnt]['is_active'] = 'enable';
    						$wcfm_attributes[$acnt]['is_visible'] = 'enable';
    					}
    				}
    				$taxonomy_fields[$att_taxonomy]['value'] = $wcfm_attributes;
    			}
    			return $taxonomy_fields;
    		}, 50, 2);

    Is it possible to make that 3 snippets work correctly together ?

  • #106513
    Avatar
    Sushobhan
    Keymaster

    Hello,
    Please use the following snippet for that –

    add_filter( 'wcfm_product_custom_attributes', function( $taxonomy_fields, $att_taxonomy ) {
        if ( isset( $taxonomy_fields[$att_taxonomy] ) && isset( $taxonomy_fields[$att_taxonomy]['value'] ) ) {
            $attributes = $taxonomy_fields[$att_taxonomy]['value'];
            $wcfm_attributes = array();
            if ( ! empty( $attributes ) ) {
                foreach ( $attributes as $acnt => $wcfm_attribute ) {
                    $wcfm_attributes[$acnt] = $wcfm_attribute;
                    $wcfm_attributes[$acnt]['is_active'] = 'enable';
                    $wcfm_attributes[$acnt]['is_visible'] = 'enable';
                }
            }
            $taxonomy_fields[$att_taxonomy]['value'] = $wcfm_attributes;
        }
        if ( isset( $taxonomy_fields[$att_taxonomy] ) && isset( $taxonomy_fields[$att_taxonomy]['options'] ) ) {
            if ( isset( $taxonomy_fields[$att_taxonomy]['options']['is_active'] ) ) {
                $taxonomy_fields[$att_taxonomy]['options']['is_active']['custom_attributes'] = array( 'required' => 1, 'attrlimit' => 1, 'required_message' => 'Attributes are required' );
            }
            if ( isset( $taxonomy_fields[$att_taxonomy]['options']['value'] ) ) {
                $taxonomy_fields[$att_taxonomy]['options']['value']['custom_attributes'] = array( 'required' => 1, 'attrlimit' => 1, 'required_message' => 'Attributes are required' );
            }
        }
        return $taxonomy_fields;
    }, 50, 2 );

    Thanks

You must be logged in to reply to this topic.