Support

Account

Forum Replies Created

  • Actually, there is a solution, but I didn’t have enough time to realize it through acf, maybe this will help someone to realize this task.
    And so: on the page of creating/editing taxonomy (attribute), custom form, which has hooks:
    woocommerce_after_edit_attribute_fields – for the attribute edit page.
    woocommerce_after_add_attribute_fields – for the add attribute page.

    I can add a custom input \select \anything through this hook, and then, on the admin_init hook (for example), check $_POST and if my input is there (if my input is there, there will be other inputs from the form), save this value in the database table. You can save it anywhere, but it is more correct to save it in a custom table, and create a link, for example, by the key (slug) of the attribute, for example pa_finish. And as a result, when processing a product or a taxonomy term, we can take the slug of the taxonomy (attribute) and use it in the custom table in the database to get the value that we attached to the form of creating/editing the attribute.
    Thus, I can save primitive data, such as select to specify the type of display attribute (image \ color \ text \ select) and based on this, display the necessary html for a particular attribute.

    John Huebner – I’ve seen a lot of your posts, and I think you can do it).

  • I have a piece of code that adjusts the query request for the select2 field through js

  • If you want to change the output results from the select2 field, and set conditions on js, you need to do it differently. I’m sorry, I use a translator to communicate with you (I’m from Ukraine), so I may not fully understand your question correctly.

  • If you could show me your code, maybe I could help you.

  • It`s must be working, i use this code in my project.
    Can you show you code here?
    And maybe i can write you task?

  • I managed to change the arguments for the relationship field, and get the result based on them. Task: I have Users, And I also have CPT Teams – when creating a user, I assign him a role, for example: Reporter and I, in the relation field, should pull up Teams whose selection field is equal to Reporter.

    JS:

    acf.addFilter('relationship_ajax_data', function (ajaxData, field){
    
                if(ajaxData.field_key == "field_63599162ef1ea"){
    
                    if($('body div[data-key="field_6315dc672e038"]').length > 0){
    
                        let roles = [];
    
                        $('body div[data-key="field_6315dc672e038"] .acf-checkbox-list li input').each(function (i,e){
                            if($(this).is(':checked')){
                                roles.push($(this).val());
                            }
                        });
    
                        ajaxData.meta_key = 'team_role';
                        ajaxData.meta_value = roles;
    
                    }
    
                    console.log(ajaxData);
    
                }
    
                return ajaxData;
            });

    PHP
    add_filter('acf/fields/relationship/query/name=user_teams', [$this, 'lh_acf_fields_relationship_query'], 10, 3);

    public function lh_acf_fields_relationship_query($args, $field, $post_id)
    	{
    
    		if(isset($_POST) && !empty($_POST)){
    
    			if(isset($_POST['field_key']) && $_POST['field_key'] == 'field_63599162ef1ea'){
    
    				if(isset($_POST['meta_key']) && !empty($_POST['meta_key']) &&
    					isset($_POST['meta_value']) && !empty($_POST['meta_value'])){
    
    					$args['meta_query'] = [
    						'relation' => 'AND',
    						[
    							'key' => sanitize_text_field($_POST['meta_key']),
    							'value' => $_POST['meta_value'],
    							'compare' => 'IN'
    						]
    					];
    
    				}
    
    			}
    
    		}
    
    		return $args;
    	}
Viewing 6 posts - 1 through 6 (of 6 total)