Skip to content

Instantly share code, notes, and snippets.

@vimes1984
Created July 1, 2015 19:43
Show Gist options
  • Select an option

  • Save vimes1984/532347bea69ec183c2f4 to your computer and use it in GitHub Desktop.

Select an option

Save vimes1984/532347bea69ec183c2f4 to your computer and use it in GitHub Desktop.
public function addattribute($csvvalue, $attvalue, $attname, $position){
$attheight = get_term_by( 'name', $csvvalue, $attvalue );
if(!$attheight){
$attheightnew = wp_insert_term( $csvvalue, $attvalue);
$attheightnewtest = get_term_by( 'id', $attheightnew['term_id'], $attvalue );
$product_attributes = array(
//Make sure the 'name' is same as you have the attribute
'name' => $attvalue,
'value' => $csvvalue,
'position' => $position,
'is_visible' => 1,
'is_variation' => 0,
'is_taxonomy' => 1,
);
echo "doesn't exist.. </br>";
echo "<pre>";
var_dump($attheightnewtest);
var_dump($attheightnewget);
echo "</pre>";
wp_set_object_terms( $post_id, $attheightnewtest->term_id, $attvalue );
}else{
//Type attribute
$product_attributes = array(
//Make sure the 'name' is same as you have the attribute
'name' => $attvalue,
'value' => $csvvalue,
'position' => $position,
'is_visible' => 1,
'is_variation' => 0,
'is_taxonomy' => 1,
);
wp_set_object_terms( $post_id, $attheight->term_id, $attvalue );
}
return $product_attributes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment