In Woocommerce I have a Product Attribute called "Platform" the Value of the Attribute is "Steam":
So I am bulk importing the products and the Attributes are already there.
But now I have to set for every product manually the category. Is it possible to set the Value automatically as Product Category in a function?
This Function is returning me the Attribute value right?
function get_attribute_value_from_name( $name ){
global $wpdb;
$name = 'Platform';
$attribute_value = $wpdb->get_var("SELECT attribute_value
FROM {$wpdb->prefix}woocommerce_attribute_taxonomies
WHERE attribute_name LIKE '$name'");
return $attribute_value;
}
And now how to set the value for product category?
EDIT:
$product = wc_get_product($id); //LOAD PRODUCT
global $product_attribute; //VARIABLE
$product_attribute = $product->get_attribute( 'Platform' ); //GET ATTRIBUTE OF PLATFORM
wp_set_object_terms( $post_id, $product_attribute, 'product_cat' ); //WRITE IT AS CATEGORY
$product->save(); //SAVE PRODUCT
does this make sense?