Hi guys,
Last time I managed to work around this attribute thing so that I can use the old layout/function rather than the new one by adding <?php WCVendors_Pro_Product_Form::attributes( $object_id, true ); ?> to the product-edit.php and replacing the “Save Attribute” code in the class-wcvendors-pro-product-controller.php with the code below and it worked perfectly.
Now that I have updated to the new pro version, I did the same thing with the codes but now when a vendor tries to select an attribute and save. the product comes through to Admin as it should but for some reason, the attribute value is a number rather than the text value that was selected. and when you go and edit that on the front end and select another value (i.e. Door) it generates another number instead. So it seems to be creating random numbers instead of the value selected.
Hope this makes sense. My question is, did you guys change something on this file or any other files that controlls the attributes since the last update that I need to look at and perhaps amend etc?
Here is the code that I mentioned above which I have inserted into the product-controller file:
// Save Attributes
$attributes = array();
if ( isset( $_POST[‘attribute_names’] ) && isset( $_POST[‘attribute_values’] ) ) {
$attribute_names = $_POST[‘attribute_names’];
$attribute_values = $_POST[‘attribute_values’];
$attribute_names_count = sizeof( $attribute_names );
if ( isset( $_POST[‘attribute_variation’] ) ) {
$attribute_variation = $_POST[‘attribute_variation’];
}
$pos = 0;
for ( $i = 0; $i < $attribute_names_count; $i++ ) {
if ( ! $attribute_names[ $i ] ) {
continue;
}
$is_variation = isset( $attribute_variation[ $i ] ) ? 1 : 0;
if ( isset( $attribute_values[ $i ] ) ) {
// Select based attributes – Format values (posted values are slugs)
$values = array_map( ‘sanitize_title’, $attribute_values[ $i ] );
// Remove empty items in the array
$values = array_filter( $values, ‘strlen’ );
} else {
$values = array();
}
// Update post terms
if ( taxonomy_exists( $attribute_names[ $i ] ) ) {
wp_set_object_terms( $post_id, $values, $attribute_names[ $i ] );
}
if ( $values ) {
// Add attribute to array, but don’t set values
// TODO: add filters for position, visible
$attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array(
‘name’ => wc_clean( $attribute_names[ $i ] ),
‘value’ => ”,
‘position’ => $pos,
‘is_visible’ => 1,
‘is_variation’ => $is_variation,
‘is_taxonomy’ => 1
);
}
$pos++;
}
}
if ( ! function_exists( ‘attributes_cmp’ ) ) {
function attributes_cmp( $a, $b ) {
if ( $a[‘position’] == $b[‘position’] ) {
return 0;
}
return ( $a[‘position’] < $b[‘position’] ) ? -1 : 1;
}
}
uasort( $attributes, ‘attributes_cmp’ );
update_post_meta( $post_id, ‘_product_attributes’, $attributes );