• Resolved deuf9912

    (@deuf9912)


    Hi,

    we have set up additional fields via ACF Pro per variation. Since my last update, all variation fields that we have used in our feed have been set to blanc. All variation field options are gone from the dropdown menu.

    Is there any solution but to rollback to an older version?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi,

    Thanks for using our plugin and reaching out to us.

    Can you send us some screenshots of the ACF fields you created so we can try to create those ACF fields ourselves and see if we can add it to a feed.

    Thread Starter deuf9912

    (@deuf9912)

    Hi, thank you for your reply. We have manually added the field location inside variations via functions.php. This used to work perfectly, but all fields inside product feed pro regarding this location have disapperared after updating.

    
    //ACF extension for product variations
    // Add "Product Variation" location rule values
    function my_acf_location_rule_values_post_type($choices){
    
    	$keys = array_keys($choices);
    	$index = array_search('product', $keys);
    
    	$position = $index === false ? count($choices) : $index + 1;
    
    	$choices = array_merge(
    		array_slice($choices, 0, $position),
    		array('product_variation' => __('Product Variation', 'auf')),
    		array_slice($choices, $position)
    	);
    
    	return $choices;
    }
    
    add_filter('acf/location/rule_values/post_type', 'my_acf_location_rule_values_post_type');
    
    // Add "Product Variation" location rule match
    function my_acf_location_rule_match_post_type($match, $rule, $options, $field_group){
    
    	if ($rule['value'] == 'product_variation') {
    		$post_type = $options['post_type'];
    
    		if ($rule['operator'] == "==")
    			$match = $post_type == $rule['value'];
    
    		elseif ($rule['operator'] == "!=")
    			$match = $post_type != $rule['value'];
    	}
    
    	return $match;
    }
    
    add_filter('acf/location/rule_match/post_type', 'my_acf_location_rule_match_post_type', 10, 4);
    // Render fields at the bottom of variations - does not account for field group order or placement.
    add_action( 'woocommerce_product_after_variable_attributes', function( $loop, $variation_data, $variation ) {
        global $abcdefgh_i; // Custom global variable to monitor index
        $abcdefgh_i = $loop;
        // Add filter to update field name
        add_filter( 'acf/prepare_field', 'acf_prepare_field_update_field_name' );
        
        // Loop through all field groups
        $acf_field_groups = acf_get_field_groups();
        foreach( $acf_field_groups as $acf_field_group ) {
            foreach( $acf_field_group['location'] as $group_locations ) {
                foreach( $group_locations as $rule ) {
                    // See if field Group has at least one post_type = Variations rule - does not validate other rules
                    if( $rule['param'] == 'post_type' && $rule['operator'] == '==' && $rule['value'] == 'product_variation' ) {
                        // Render field Group
                        acf_render_fields( $variation->ID, acf_get_fields( $acf_field_group ) );
                        break 2;
                    }
                }
            }
        }
        
        // Remove filter
        remove_filter( 'acf/prepare_field', 'acf_prepare_field_update_field_name' );
    }, 10, 3 );
    
    // Filter function to update field names
    function  acf_prepare_field_update_field_name( $field ) {
        global $abcdefgh_i;
        $field['name'] = preg_replace( '/^acf\[/', "acf[$abcdefgh_i][", $field['name'] );
        return $field;
    }
        
    // Save variation data
    add_action( 'woocommerce_save_product_variation', function( $variation_id, $i = -1 ) {
        // Update all fields for the current variation
        if ( ! empty( $_POST['acf'] ) && is_array( $_POST['acf'] ) && array_key_exists( $i, $_POST['acf'] ) && is_array( ( $fields = $_POST['acf'][ $i ] ) ) ) {
            foreach ( $fields as $key => $val ) {
                update_field( $key, $val, $variation_id );
            }
        }
    }, 10, 2 );
    
    //make variation fields displayable
    function custom_variation_fields ($variations) {
      $variations['variation_ingredients'] = get_field('variation_ingredients', $variations[ 'variation_id']);
    
      return $variations;
    }
    add_filter('woocommerce_available_variation', 'custom_variation_fields', 10, 1);

    `

    • This reply was modified 4 years, 5 months ago by deuf9912.
    • This reply was modified 4 years, 5 months ago by deuf9912.

    Hi,

    In release 11.0.2 of our plugin we replaced an “old fashioned” WP-sql-query with a build in WordPress function get_post_custom_keys which is more efficient and faster than the query we used. This seems to work for all users, apart from you who added fields in the functions.php.

    We tested fields that were added by using the ACF (PRO) version and that continued to work perfectly fine. Unfortunately adding field directly in the functions.php is not something we can support.

    Thread Starter deuf9912

    (@deuf9912)

    Thank you for your reply.
    But how do you suggest to add fields to product variations? I need to add custom attributes to my feeds, that differ by variation.

    I have simply added a ACF field location, not the fields itself via functions.php. The field contents still are stored in the same location, as post meta entry under the corresponding post id (=variation ID).

    What can I do to have variation fields recognized in my feed configuration?

    i can second this,
    i also use a special plugin
    WooCommerce Custom Fields for Variations by Iconic
    to add custom fields to each variation

    because acf wont allow custom fields for each variation, and

    i also have to use version 11.0.1, in order to get these fields to appear, which is very frustrating, because i have paid for the elite version also,
    so im currently stuck using 11.0.1 in pro version,

    you guys need to find a way to get these to reappear.
    in the list.

    (co-incidently, for some reason, after swapping between pro 11.0.1 and the latest elite version a few times, 1 of my custom fields has stayed available to use in the elite version, but the others have not appeared,
    needs looking into

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Variation fields missing from feed since update’ is closed to new replies.