WC_Meta_Box_Product_Data::prepare_set_attributes PHP Method

prepare_set_attributes() private static method

Prepare attributes for a specific variation or defaults.
private static prepare_set_attributes ( array $all_attributes, string $key_prefix = 'attribute_', integer $index = null ) : array
$all_attributes array
$key_prefix string
$index integer
return array
    private static function prepare_set_attributes($all_attributes, $key_prefix = 'attribute_', $index = null)
    {
        $attributes = array();
        if ($all_attributes) {
            foreach ($all_attributes as $attribute) {
                if ($attribute->get_variation()) {
                    $attribute_key = sanitize_title($attribute->get_name());
                    if (!is_null($index)) {
                        $value = isset($_POST[$key_prefix . $attribute_key][$index]) ? stripslashes($_POST[$key_prefix . $attribute_key][$index]) : '';
                    } else {
                        $value = isset($_POST[$key_prefix . $attribute_key]) ? stripslashes($_POST[$key_prefix . $attribute_key]) : '';
                    }
                    $value = $attribute->is_taxonomy() ? sanitize_title($value) : wc_clean($value);
                    // Don't use wc_clean as it destroys sanitized characters in terms.
                    $attributes[$attribute_key] = $value;
                }
            }
        }
        return $attributes;
    }