Title: attribute variation issues
Last modified: August 11, 2019

---

# attribute variation issues

 *  [waheed146](https://wordpress.org/support/users/waheed146/)
 * (@waheed146)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/attribute-variation-issues-2/)
 * Hello,
 * when select a variable product to add to cart it is not selected and says invalid
   value for attribute.
    if i am missing something or need to modify please let 
   me know
 *  if ($attributes = $oscdb->get_results(“select pa.price_prefix, pa.options_values_price,
   po.products_options_name, pov.products_options_values_name FROM products_attributes
   pa, products_options po, products_options_values pov WHERE pa.products_id='”.
   $product[‘products_id’].”‘ AND pov.products_options_values_id = pa.options_values_id
   AND pov.language_id=po.language_id AND po.language_id=1 AND pa.options_id=products_options_id”,
   ARRAY_A)) {
 *  wp_set_object_terms($product_id, ‘variable’, ‘product_type’);
    $attrib_array
   = array(); $attrib_combo = array(); $max_price = $product[‘products_price’]; 
   $min_price = $product[‘products_price’]; foreach ($attributes as $attribute) {
   $slug = sanitize_title($attribute[‘products_options_name’]); $attrib_array[$slug]
   = array( ‘name’ => $attribute[‘products_options_name’], ‘value’ => ltrim($attrib_array[
   $slug][‘value’] . ‘ | ‘ . $attribute[‘products_options_values_name’], ‘ | ‘),‘
   position’ => 0, ‘is_visible’ => 1, ‘is_variation’ => 1, ‘is_taxonomy’ => 0); 
   if($attribute[‘price_prefix’] == ‘-‘)$attributeprefix = ‘-‘; else if($attribute[‘
   price_prefix’] == ‘+’)$attributeprefix = ‘+’; else $attributeprefix = ”; $attrib_combo[
   $slug][] = array($attribute[‘products_options_values_name’], $attributeprefix.
   $attribute[‘options_values_price’]); } // Now it gets tricky… $combos = otw_cartesian_product(
   $attrib_combo);
 *  foreach ($combos as $combo) {
 *  $variation_id = wp_insert_post(array(
    ‘post_title’ => ‘Product ‘ . $product_id.‘
   Variation’, ‘post_content’ => ”, ‘post_status’ => ‘publish’, ‘post_type’ => ‘
   product_variation’, ‘post_author’ => 1, ‘post_parent’ => $product_id ));
 *  $opt_price = $product[‘products_price’] .$attributeprefix. $attribute[‘options_values_price’];
   
   $special_price = $special[‘specials_new_products_price’];
 *  foreach ($combo as $k => $v) {
 *  update_post_meta($variation_id, ‘attribute_’ . $k, $v[0]);
    $opt_price += $v[
   1]; $special_price += $v[1]; }
 *  update_post_meta($variation_id, ‘_sku’, ” );
    update_post_meta($variation_id,‘
   _regular_price’, $opt_price); update_post_meta($variation_id, ‘_price’, $opt_price);
   update_post_meta($variation_id, ‘_thumbnail_id’, 0); update_post_meta($variation_id,‘
   _stock’, $product[‘products_quantity’]); if ($special) { update_post_meta($variation_id,‘
   _sale_price’, $special_price); if ($special[‘expires_date’] > time()) { update_post_meta(
   $variation_id, ‘_sale_price_dates_to’, date(“Y-m-d”, $special[‘expires_date’]));
   update_post_meta($variation_id, ‘_sale_price_dates_from’, date(“Y-m-d”)); } }
   if ($opt_price > $max_price) { $max_price = $opt_price; } if ($opt_price < $min_price){
   $min_price = $opt_price; } }
 *  update_post_meta($product_id, ‘_product_attributes’, $attrib_array);
    update_post_meta(
   $product_id, ‘_max_variation_regular_price’, $max_price); update_post_meta($product_id,‘
   _min_variation_regular_price’, $min_price); update_post_meta($product_id, ‘_max_variation_price’,
   $max_price); update_post_meta($product_id, ‘_min_variation_price’, $min_price);}

The topic ‘attribute variation issues’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/woo-oscommerce-sync.svg)
 * [Woocommerce osCommerce Sync](https://wordpress.org/plugins/woo-oscommerce-sync/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woo-oscommerce-sync/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woo-oscommerce-sync/)
 * [Active Topics](https://wordpress.org/support/plugin/woo-oscommerce-sync/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woo-oscommerce-sync/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woo-oscommerce-sync/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [waheed146](https://wordpress.org/support/users/waheed146/)
 * Last activity: [6 years, 8 months ago](https://wordpress.org/support/topic/attribute-variation-issues-2/)
 * Status: not resolved