Forums Forums Search & Filter Pro Search for custom fields

Viewing 2 posts - 1 through 2 (of 2 total)
  • Anonymous
    #35201

    Is this possible?
    I deeply modified my woocommerce website to allow interaction with my company webservices.
    Actually I add products programmatically reading values from a webservice and adding later custom detailed fields.
    In particular my products are tyres and wheels.
    Here a screenshot of how I do that:

    foreach($product->children() as $field)
    	{
    		if($field->getName() != 'Value' && $field->getName() != 'Description' && $field->getName() != 'ProductImage')
    		{	
    			$fieldName = (string)$field->getName();
    			add_custom_product_attributes($product_attributes, $fieldsArray[$fieldName]->caption, $fieldsArray[$fieldName]->tab, (string)$field); 
    		}
    	}
    update_post_meta( $post_id, '_product_attributes', $product_attributes); // very important for custom fields
    
    function add_custom_product_attributes(&$product_attributes, $name, $value, $tab='Main informations', $position = 1, $is_visible = 1, $is_variable = 1, $is_taxonomy = 0)
    {
    	$product_attributes[$name] = array(
            //Make sure the 'name' is same as you have the attribute
            'name' => htmlspecialchars(stripslashes($name)),
            'value' => $value,
            'position' => $position,
            'is_visible' => $is_visible,
            'is_variation' => $is_variable,
            'is_taxonomy' => $is_taxonomy,
    		'tab' => $tab
        );
    }

    I’d like to filter for these ‘product_attributes’. Is there a way? if I try to add the related meta field I can only the meta product_attributes even if it’s an array. I need to access puntually to these array fields.

    I hope you can help me.

    Thanks in advance,
    Fabio

    Ross Moderator
    #35266

    Hey Fabio

    I think I follow you, you are trying to auto-import posts, but the new posts & values/attributes don’t appear in S&F?

    In this case, after a post has been updated (and had an attribute added to it), make sure to call:

    do_action('search_filter_update_post_cache', 1984);

    Where 1984 is the ID of your post.

    This should keep everything in sync 🙂

    Thanks

Viewing 2 posts - 1 through 2 (of 2 total)