I have products from some API and want to insert these products. I was able to insert products and use already existing attributes ( or added by UI ).

Adding new term (My Color) to the existing attribute (Color) :

// Add term to the attribute
wp_set_object_terms( $post_id, "My Color", 'pa_color' , true );

Use the added attribute with current product :

// Data for the term to be used
$theData = array(
                       'value'='My Color',
                       'is_visible' => '1',
                       'is_variation' => '1',
                       'is_taxonomy' => '1'

// Add this attribute to this product
update_post_meta( $post_id,'_product_attributes',$theData);

How can I add new attribute and use it with the current product, for ex :


I have tried this :

            'label' => __( 'RAM' ),
            'rewrite' => array( 'slug' => 'size' ),
            'hierarchical' => true,

Here is the URL of the attributes I can see/add in UI :


enter image description here

  • Did you managed to fix this? – Jordy Mar 15 '18 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.