Allow only one attribute for product

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Viewing 9 reply threads
  • Author
    Posts
    • #110155
      contatoapp
      Participant

      I’d like to know if it’s possible to store vendors to add only one attribute to their products. I could use CSS to hide the “Add all” button but they can still open the dropdown menu and add another attribute. The specified attributes refer to the items condition (mint, near-mint, used) so users could filter products on my marketplace by their condition, but I don’t want store vendors to add several attributes cause it wouldn’t make any sense.

      Attachments:
      You must be logged in to view attached files.
    • #110260
      Sushobhan
      Keymaster

      Hello,
      Kindly use the following snippet-

      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/

    • #110729
      contatoapp
      Participant

      Hi. I’ve used Code Snipepts to add this code but vendors are still able to add more than one attribute. Please see the attached screenshots:

      Attachments:
      You must be logged in to view attached files.
    • #110944
      Sushobhan
      Keymaster

      Hello,
      It seems the product is already published before the code snippet was added. From now on, when you try to add a new product, you will see that you can’t add more than one attribute.
      Thanks!

    • #110974
      contatoapp
      Participant

      Hi. I’ve published another product and I’m still able to add more than one attribute. Please see screenshots.

      Attachments:
      You must be logged in to view attached files.
    • #111165
      Sushobhan
      Keymaster

      Hello,
      Have you use my snippet in your themes function.php? Well, the snippet should work. To debug this further I’ll require a temporary access of your site. When sharing the access, please don’t forget to mark the reply as private.
      Thanks!

    • #111226
      contatoapp
      Participant
      This reply has been marked as private.
    • #111302

      Hello,

      We have disabled the “Mandatory attributes” snippets.(PFA)
      This code is creating the issue.Now is working fine.

      Thanks.

      Attachments:
      You must be logged in to view attached files.
    • #111383
      contatoapp
      Participant

      Hi. It’s good that is working now, but I also deemed that snippet necessary. That way vendors wouldn’t create a product without selecting an attribute. Is there no way to allow only one attribute and also make it required that vendores add an attribute?

      • #111834
        Sushobhan
        Keymaster

        Hello,
        Kindly use the following snippet instead-

        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, '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!

        • #111840
          contatoapp
          Participant

          Hi. Could you check my question down below about translating the “You can only select 1 item” string when adding attributes?

    • #111514
      contatoapp
      Participant

      Also, where can I translate this string? I’ve found the exact same one on Loco Translate for WCFM – WooCommerce Frontend Manager but it did not apply for this message.

      Attachments:
      You must be logged in to view attached files.
Viewing 9 reply threads
  • You must be logged in to reply to this topic.