Title: programmatically make an attribute a variation
Last modified: August 20, 2016

---

# programmatically make an attribute a variation

 *  [Fotis](https://wordpress.org/support/users/markwaregr/)
 * (@markwaregr)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/programmatically-make-an-attribute-a-variation/)
 * hello how can i make an attribute of a product a variation with custom price 
   but programmatically.
 * [http://wordpress.org/extend/plugins/woocommerce/](http://wordpress.org/extend/plugins/woocommerce/)

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

 *  [jrgd](https://wordpress.org/support/users/jrgd/)
 * (@jrgd)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/programmatically-make-an-attribute-a-variation/#post-3243989)
 * hi mark, it seems i’m following your steps on this topic, on stackoverflow and
   here—did you manage to get this working?
 * i’m stuck with the creation of attributes and their terms
    can you shed some 
   light?
 *  Thread Starter [Fotis](https://wordpress.org/support/users/markwaregr/)
 * (@markwaregr)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/programmatically-make-an-attribute-a-variation/#post-3243990)
 * hi yes i did, i posted it in wordpress overflow, i really forgot to post it here
   also!
 * Found the solution to make a product attribute, a variation. Lets say we have
   wp_set_object_terms( $post_id, ‘XL’, ‘pa_size’ ); The above is a custom attribute(
   a size attribute). Making it a variation will look like
    $new_post = array( ‘
   post_title’ => “Custom Variable”, ‘post_content’ => ‘Lorem ipsum dolor sit amet…’,‘
   post_status’ => ‘publish’, ‘post_type’ => ‘product’ );
 * $skuu = “random”;
    $post_id = wp_insert_post($new_post); update_post_meta($post_id,‘
   _sku’, $skuu ); update_post_meta( $post_id, ‘_price’, “25” );
 * //made it variable but variations wont be added!
    wp_set_object_terms ($post_id,‘
   variable’, ‘product_type’); wp_set_object_terms( $post_id, ‘XL’, ‘pa_size’ );/*
   the solution is here under */ $thedata = Array(‘pa_size’=>Array( ‘name’=>’pa_size’,‘
   value’=>”, ‘is_visible’ => ‘1’, ‘is_variation’ => ‘1’, ‘is_taxonomy’ => ‘1’ ));
   update_post_meta( $post_id,’_product_attributes’,$thedata);
 * /* end of my solution */
 * update_post_meta( $post_id, ‘_visibility’, ‘search’ );
    update_post_meta( $post_id,‘
   _stock_status’, ‘instock’);
 * so now you have it pa_size its a variation

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

The topic ‘programmatically make an attribute a variation’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [attributes](https://wordpress.org/support/topic-tag/attributes/)
 * [variations](https://wordpress.org/support/topic-tag/variations/)

 * 2 replies
 * 2 participants
 * Last reply from: [Fotis](https://wordpress.org/support/users/markwaregr/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/programmatically-make-an-attribute-a-variation/#post-3243990)
 * Status: not resolved