• Resolved codimex

    (@codimex)


    Hi! My love for Forminator will go ooonn and ooonnn!!! I’m trying to limit the dropdown category selection to one value in a product frontend creation form, in order to prevent my client to mess things up. In my case, the only product category id I want to be dropdowned -and therefore, selected by default- is 30. This solution doesn’t work entirely for me, despite it seems a brilliant code snippet. Any hint to point me towards the right direction? Thank you!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @codimex,

    Trust you are doing good and thank you for reaching out to us.

    Can you please explain if you have noticed any issues while using the mentioned code?

    Please also share an export of your form so we could help you better. You should share the export of the form using Google Drive or Dropbox. Please find how to export a form in our documentation here: https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#import-export

    We look forward to hearing back from you.

    Kind Regards,
    Nebu John

    Thread Starter codimex

    (@codimex)

    Hi! I really doubt my form export will be useful for this case (you need the Woocommerce structure as well), but, anyway, here you go:

    {"type":"form","data":{"fields":[{"id":"postdata-1","element_id":"postdata-1","form_id":"wrapper-1511347711918-1669","parent_group":"","type":"postdata","cols":"12","data_status":"draft","post_title_label":"Post Title","post_content_label":"Post Content","post_excerpt_label":"Post Excerpt","post_image_label":"Featured Image","category_label":"Category","post_tag_label":"Tags","select_author":"1","category_multiple":"0","post_tag_multiple":"0","post_type":"product","post_title":"1","post_content":"1","category":"1","post_image":"1","options":[{"label":"","value":""}],"wrapper_id":"wrapper-1511347711918-1669","product_cat":"1"}],"settings":{"pagination-header":"nav","paginationData":{"pagination-header-design":"show","pagination-header":"nav"},"formName":"Product submission","version":"1.22.1","form-border-style":"none","form-padding":"","form-border":"","fields-style":"open","validation":"on_submit","akismet-protection":"1","form-style":"default","enable-ajax":"true","autoclose":"true","submission-indicator":"show","indicator-label":"Submitting...","form-type":"default","submission-behaviour":"behaviour-thankyou","thankyou-message":"Thank you. Your post has been submitted.","submitData":{"custom-submit-text":"Submit product","custom-invalid-form-message":"Error: Your form is not valid, please fix the errors!"},"validation-inline":"1","form-expire":"no_expire","form-padding-top":"0","form-padding-right":"0","form-padding-bottom":"0","form-padding-left":"0","form-border-width":"0","form-border-radius":"0","cform-label-font-family":"Roboto","cform-label-custom-family":"","cform-label-font-size":"12","cform-label-font-weight":"bold","cform-title-font-family":"Roboto","cform-title-custom-family":"","cform-title-font-size":"45","cform-title-font-weight":"normal","cform-title-text-align":"left","cform-subtitle-font-family":"Roboto","cform-subtitle-custom-font":"","cform-subtitle-font-size":"18","cform-subtitle-font-weight":"normal","cform-subtitle-text-align":"left","cform-input-font-family":"Roboto","cform-input-custom-font":"","cform-input-font-size":"16","cform-input-font-weight":"normal","cform-radio-font-family":"Roboto","cform-radio-custom-font":"","cform-radio-font-size":"14","cform-radio-font-weight":"normal","cform-select-font-family":"Roboto","cform-select-custom-family":"","cform-select-font-size":"16","cform-select-font-weight":"normal","cform-multiselect-font-family":"Roboto","cform-multiselect-custom-font":"","cform-multiselect-font-size":"16","cform-multiselect-font-weight":"normal","cform-dropdown-font-family":"Roboto","cform-dropdown-custom-font":"","cform-dropdown-font-size":"16","cform-dropdown-font-weight":"normal","cform-calendar-font-family":"Roboto","cform-calendar-custom-font":"","cform-calendar-font-size":"13","cform-calendar-font-weight":"normal","cform-button-font-family":"Roboto","cform-button-custom-font":"","cform-button-font-size":"14","cform-button-font-weight":"500","cform-timeline-font-family":"Roboto","cform-timeline-custom-font":"","cform-timeline-font-size":"12","cform-timeline-font-weight":"normal","cform-pagination-font-family":"","cform-pagination-custom-font":"","cform-pagination-font-size":"16","cform-pagination-font-weight":"normal","payment_require_ssl":"","submission-file":"delete","store_submissions":"1","form_name":"product-submission","form_status":"publish"},"client_id":null,"integration_conditions":[],"behaviors":[{"slug":"behavior-1234-4567","label":"","autoclose-time":"5","autoclose":"true","newtab":"sametab","thankyou-message":"Thank you. Your post has been submitted.","email-thankyou-message":"","manual-thankyou-message":"","submission-behaviour":"behaviour-thankyou","redirect-url":""}],"notifications":[]},"status":"publish","version":"1.22.1"}

    As I said, you should probably need the WooCommerce structure to check your code snippet to include certain product categories works. I don’t think this code…

    add_filter( 'forminator_field_postdata_category_list', function( $categories ){
    	$only_cat_ids = [
    		123,
    		456
    	];
    		foreach( $categories as $id => $cat ){
    			if( ! in_array( $cat->term_id, $only_cat_ids ) ){
    				unset( $categories[ $id ] );
    			}
    		}
    	return $categories;
    } );

    …is valid for product categories, just for regular post categories. If that is the case, which one would be the right syntax? Thank you!

    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @codimex

    By default, Forminator can cover only default post categories. As for WooCommerce, it could be too complex. However, I pinged our SLS Team to review your query and see if we can help in this matter. We will post an update here as soon as more information is available.

    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi again @codimex

    For woocomerce product category we have to just change the taxonomy name in the filter from category to product_cat
    Please try following snippet:

    add_filter( 'forminator_field_postdata_product_cat_list', function( $categories ){
    	$only_cat_ids = [
    		117,
    	];
    		foreach( $categories as $id => $cat ){
    			if( ! in_array( $cat->term_id, $only_cat_ids ) ){
    				unset( $categories[ $id ] );
    			}
    		}
    	return $categories;
    } );

    Only need now is to change 117 to your product category ID.

    Kind Regards,
    Kris

    Thread Starter codimex

    (@codimex)

    You guys really rock! The snippet works as magic! I suspected product_cat should be involved somewhere around, but couldn’t find exactly where. Thank you so much, Kris!!! Marking as happily resolved!

    Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hi @codimex

    Thanks for confirming the snippet provided by Kris worked just fine. If you need help with another request please feel free to open a new ticket. The team will be glad to provide further assistance.

    Kind regards

    Luis

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Forminator product frontend creation – Limiti to one category’ is closed to new replies.